5 Replies Latest reply on Apr 19, 2010 11:58 PM by joe.marques

    Problem with TreeStateAdvisor

    kA kA Newbie

      Hi,

      I have a problem with the stateAdvisor attribute in my tree.
      When I click on a tree node very often in a short time it results (after a while) in a NullPointerException.

      Here is the relavant code:


      <rich:tree switchType="ajax" stateAdvisor="#{treeNodeStateAdvisor}">
       <rich:recursiveTreeNodesAdaptor roots="#{treeBean.rootNodes}"
       var="node" nodes="#{node.childs}">
       <rich:treeNode>
       <a4j:commandLink value="#{node.name}">
       <a4j:actionparam name="selectednodeid" value="#{node.nodeId}"
       assignTo="#{treeNodeStateAdvisor.selectedNodeId}" />
       </a4j:commandLink>
       </rich:treeNode>
       </rich:recursiveTreeNodesAdaptor>
      </rich:tree>



      public class TreeNodeStateAdvisor implements TreeStateAdvisor {
      
       private Long selectedNodeId;
      
       @Override
       public Boolean adviseNodeOpened(UITree tree) {
       if(((TreeNode)tree.getRowData()).getNodeId().equals(selectedNodeId)) {
       return true;
       }
       return null;
       }
      
       @Override
       public Boolean adviseNodeSelected(UITree tree) {
       return null;
       }
      
       public Long getSelectedNodeId() {
       return selectedNodeId;
       }
      
       public void setSelectedNodeId(Long selectedNodeId) {
       this.selectedNodeId = selectedNodeId;
       }
      
      }


      As you can see I use the a4j:actionparam tag to set the selectedNodeId variable.

      This exception does occur:

      13:07:18,246 ERROR [ExceptionFilter] handling uncaught exception
      javax.servlet.ServletException: java.lang.NullPointerException
       at javax.faces.webapp.FacesServlet.service(FacesServlet.java:256)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
       at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:85)
       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
       at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
       at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
       at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:147)
       at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:276)
       at org.ajax4jsf.Filter.doFilter(Filter.java:175)
       at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56)
       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
       at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:58)
       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
       at org.jboss.seam.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.java:68)
       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
       at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
       at net.sharesuite.portal.ShareSuiteFilter.doFilter(ShareSuiteFilter.java:69)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
       at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
       at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
       at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
       at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
       at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
       at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
       at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
       at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
       at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
       at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
       at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
       at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
       at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
       at java.lang.Thread.run(Thread.java:619)
      Caused by: javax.faces.FacesException: java.lang.NullPointerException
       at org.ajax4jsf.component.UIDataAdaptor.iterate(UIDataAdaptor.java:1030)
       at org.ajax4jsf.component.UIDataAdaptor.processDecodes(UIDataAdaptor.java:1119)
       at org.richfaces.component.UITree.processDecodes(UITree.java:455)
       at javax.faces.component.UIForm.processDecodes(UIForm.java:203)
       at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1001)
       at org.ajax4jsf.component.AjaxViewRoot$1.invokeContextCallback(AjaxViewRoot.java:387)
       at org.ajax4jsf.component.AjaxViewRoot.processPhase(AjaxViewRoot.java:234)
       at org.ajax4jsf.component.AjaxViewRoot.processDecodes(AjaxViewRoot.java:404)
       at com.sun.faces.lifecycle.ApplyRequestValuesPhase.execute(ApplyRequestValuesPhase.java:101)
       at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
       at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117)
       at javax.faces.webapp.FacesServlet.service(FacesServlet.java:244)
       ... 40 more
      Caused by: java.lang.NullPointerException
       at org.richfaces.component.state.TreeState$3.processNode(TreeState.java:267)
       at org.richfaces.model.StackingTreeModel.doWalk(StackingTreeModel.java:275)
       at org.richfaces.model.StackingTreeModel.walk(StackingTreeModel.java:363)
       at org.richfaces.model.AbstractTreeDataModel.walk(AbstractTreeDataModel.java:58)
       at org.ajax4jsf.component.UIDataAdaptor.walk(UIDataAdaptor.java:1112)
       at org.ajax4jsf.component.UIDataAdaptor.iterate(UIDataAdaptor.java:1028)
      


      I'm using RF 3.2.0, Jboss, Seam and Facelets
      Has anybody an idea?

      Best Regards


        • 1. Re: Problem with TreeStateAdvisor
          Vassiliy Dubkin Newbie

          We experienced the same problem today. I couldn't reproduce it until I found your posting. It occurs only sometimes if you click two or more times on an item in a tree (unfortunately, users click more than one or two times on an item :-( ). Maybe that is a richfaces bug? Can someone confirm it as a bug?

          @hebe: Could you solve this problem, or find a workaround?

          • 2. Re: Problem with TreeStateAdvisor
            Ilya Shaikovsky Master

            maybe eventQueue defined will helps?

            • 3. Re: Problem with TreeStateAdvisor
              Newbie

              I had the same problem with the tree and opening/closing nodes too quickly.  At first glance, it appears that adding the following two attributes fixed the issue:

               

              eventsQueue="someUniqueIdentifier"
              ignoreDupResponses="true"

               

              Ilya, thanks for the suggestion.

              • 4. Re: Problem with TreeStateAdvisor
                Newbie

                Acually, I spoke too soon.  Although I can now expand/collapse nodes quickly, I still get intermittent NPEs when loading / reloading this tree.

                • 5. Re: Problem with TreeStateAdvisor
                  Newbie

                  OK, so it turned out there was a bug in our adviseNodeOpened(UITree) method implementation.  The old logic was:

                   

                  public void changeExpandListener(org.richfaces.event.NodeExpandedEvent e) {

                  HtmlTree tree = (HtmlTree) e.getComponent();

                  TreeState state = (TreeState) tree.getComponentState();

                  TreeRowKey<?> key = (TreeRowKey<?>) tree.getRowKey(); // bombs here

                  if (state.getSelectedNode() != null) {
                              // do stuff

                  }

                  }

                   

                  The correct logic should be:

                   

                  public void changeExpandListener(org.richfaces.event.NodeExpandedEvent e) {

                  HtmlTree tree = (HtmlTree) e.getComponent();

                  TreeState state = (TreeState) tree.getComponentState();

                  if (state.getSelectedNode() != null) {

                  TreeRowKey<?> key = (TreeRowKey<?>) tree.getRowKey();

                  // do stuff

                  }

                  }

                   

                  Without that fix, RichFaces 3.3.3.CR1 would throw an intermittent NullPointException at:

                   

                  java.lang.NullPointerException at
                  org.richfaces.model.StackingTreeModel.getInternalModelById(StackingTreeModel.java:354) at
                  org.richfaces.model.StackingTreeModel.doSetupKey(StackingTreeModel.java:154) at
                  org.richfaces.model.StackingTreeModel.setupKey(StackingTreeModel.java:191) at
                  org.richfaces.model.StackingTreeModel.setRowKey(StackingTreeModel.java:497) at
                  org.richfaces.model.StackingTreeModel.setRowKey(StackingTreeModel.java:493) at
                  org.ajax4jsf.component.UIDataAdaptorBase.setRowKey(UIDataAdaptorBase.java:351) at
                  org.ajax4jsf.component.UIDataAdaptorBase.setRowKey(UIDataAdaptorBase.java:324) at
                  org.richfaces.renderkit.TreeRendererBase.getSelectionValue(TreeRendererBase.java:528) at
                  org.richfaces.renderkit.TreeRendererBase.encodeSelectionStateInput(TreeRendererBase.java:553)