7 Replies Latest reply on Feb 20, 2009 1:18 AM by Ingo Jobling

    Problem to keep rich:tree state

    Fábio Valente Newbie

      I'm using the Richfaces tree component, but it's collapsing when I go to a different page.
      I have this tree in several pages (I'm using the templating mechanism) and when I click on a link from the tree (I use <s:link> in every treeNode).

      I searched for a solution, but I couldn't find one.

      Here is the code of my tree:

          <rich:tree switchType="ajax">
              <rich:recursiveTreeNodesAdaptor roots="#{hierarchicalClassifier.rootElements}" 
                      var="hierarchicalElement" nodes="#{hierarchicalElement.childrenElements}">
                      <s:link value="#{hierarchicalElement.title}" view="/viewElement.xhtml" />

      I saw that the tree component has attributes called stateVar and stateAdvisor. The problem is that I don't how to use them and I didn't find examples of how to use them.

      I tried the solution given by Roberson Ribeiro that can be found here but I couldn't even startup JBoss. I get java.lang.NoClassDefFoundError: org/ajax4jsf/component/UIDataAdaptor.

      Can anyone help me?

        • 1. Re: Problem to keep rich:tree state
          blabno Master

          Info on how to use stateAdvisor is in richfaces tlddoc.

          adviseNodeOpened : javax.el.MethodExpression
          (signature must match void adviseNodeOpened(org.richfaces.component.UITree))      MethodBinding pointing at a method accepting an org.richfaces.component.UITree with return of java.lang.Boolean type. If returned value is: java.lang.Boolean. TRUE, a particular treeNode is expanded; java.lang.Boolean.FALSE, a particular treeNode is collapsed; null, a particular treeNode saves the current state

          As to NoClassDefFoundError, you do not have richfaces-ui.jar in your classpath. Put all 3 richfaces jars in EAR/lib or if you use WAR only, put it in WEB-INF/lib.

          And one more thing. When you use your tree between conversations make your advisor session scoped.

          • 2. Re: Problem to keep rich:tree state
            Vladimir Kovalyuk Apprentice

            For what reason we should include richfaces-impl.jar into ear/lib if there is richfaces-api?

            • 3. Re: Problem to keep rich:tree state
              Fábio Valente Newbie

              I solved the problem.

              I used the attribute componentState from the tree component.

              I have to show several trees at the same time and keep the state of all of them.

              So I created a controller with scope SESSION and added a Map<HierarchicalClassifier, TreeState> with getter and setter (both passing a HierarchicalClassifier argument) for the map.

              Concerning the problem of NoClassDefFoundError, I added the richfaces-ui.jar in my classpath.


              • 4. Re: Problem to keep rich:tree state
                safa said Newbie

                hi, fabio,

                I'm having the same problem,

                Can you, plz, give more details on how you resolve it??

                I really need your help


                • 5. Re: Problem to keep rich:tree state
                  Fábio Valente Newbie


                  public class TreeStateController extends Controller
                      private Map<Integer, TreeState> treeStateMap = new HashMap<Integer, TreeState>();
                      public TreeState getTreeState(Integer key)
                          TreeState treeState = treeStateMap.get(key); 
                          if (treeState == null)
                              treeState = new TreeState();
                              treeStateMap.put(key, treeState);
                          return treeState;
                      public void setTreeState(Integer key, TreeState treeState)
                          treeStateMap.put(key, treeState);


                  <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
                  <ui:composition xmlns="http://www.w3.org/1999/xhtml"
                  <rich:tree switchType="client" 
                      <rich:recursiveTreeNodesAdaptor roots="#{tree.activeRootElements}" 
                              var="element" nodes="#{element.activeChildrenElements}">
                          <s:link view="/viewElement.xhtml">
                              <f:param value="#{element.id}" name="elementId"/>
                              <h:outputText value="#{element.title}"/>
                      <a4j:support event="oncollapse" ajaxSingle="true" />
                      <a4j:support event="onexpand" ajaxSingle="true" />

                  • 6. Re: Problem to keep rich:tree state
                    Axel Osorio Newbie

                    Fabio . Thank you very much for your example, I've working on an app that requires the rich tree component state and your solution was very useful to me. Only want to say thank you.

                    • 7. Re: Problem to keep rich:tree state
                      Ingo Jobling Master

                      Fabio, Please accept my thanks also.  Your example is solid gold for me!