5 Replies Latest reply on Jan 31, 2011 10:38 AM by mt le

    Tree ignores componentState and stateAdvisor

    mt le Newbie



      I'm using RichFaces 3.3.3 and have a rich:tree component defined like this:


      <rich:tree value="#{customerTreeBuilder.rootNode}" var="node" icon="#{node.imagePath}" iconLeaf="#{node.imagePath}"
              switchType="client" componentState="#{treeStateController.customerTreeState}" binding="#{treeModel.customerTree}"
              nodeSelectListener="#{treeModel.onSelect}" stateAdvisor="#{treeStateAdvisor}">
                  <h:commandLink value="#{node.displayName}" action="#{node.getAction()}" />


      The tree is built dynamically, so #{customerTreeBuilder.rootNode} is the root node which gets children added in my bean customerTreeBuilder.


      The tree is displayed, the nodes look nice, but there seems to be a problem with the state.

      I want the nodes to be expanded by default, so I set everything up according to http://community.jboss.org/thread/16855 with my #{treeStateAdvisor}. But nothing happens. The nodes are not expanded by default ad componentState saving doesn't work either.


      Does anyone have an idea, what could cause the problem?


      Any help is appreciated

        • 2. Re: Tree ignores componentState and stateAdvisor
          Ilya Sorokoumov Master

          I don't know what's the problem with dynamical tree creation in your case. But I think you should also post some code from your beans to make it more clear for RF team.

          By the way componentState is working for me well but I'm actually using recursiveTreeNodesAdaptor in order to create tree dynamically.

          Like here:


          Do you really need to build tree in your bean or it's possible to use recursiveTreeNodesAdaptor as a workaround?

          • 3. Re: Tree ignores componentState and stateAdvisor
            mt le Newbie



            here is my bean code:



            public SimTreeNode buildTree() {
                    SimTreeNode realRoot = new SimTreeNode();
                    SimTreeNode root = new SimTreeNode();
                    SimTreeNodeData rootData = getData(kunde);
                    Collection<? extends ISimEntity> childEntities;
                    childEntities = coreFacade.getChildren(kunde);
                    addNodesRecursive(root, childEntities);
                    realRoot.addChild("ROOT", root);
                    return realRoot;
                private void addNodesRecursive(SimTreeNode parent, Collection<? extends ISimEntity> entities) {
                    if (entities == null) {
                    for (ISimEntity entity : entities) {
                        SimTreeNode newNode = new SimTreeNode();
                        SimTreeNodeData data = getData(entity);
                        Collection<? extends ISimEntity> childEntities = coreFacade.getChildren(entity);
                        parent.addChild(entity.getSimId(), newNode);
                        addNodesRecursive(newNode, childEntities);
                    }    }


            In my xhtml I call buildTree() and the tree is built dynamically. The return value is a SimTreeNode with all its children and their children and so on.


            So can anybody see, why stateSaving and stateAdvisor aren't working? Do I have to use the recursiveTreeNodeAdapter?


            Thanks for any hints

            • 4. Tree ignores componentState and stateAdvisor
              Nick Belaevski Master



              Both component state & state advisor should work either with TreeNode-based trees as with adaptor-based. How does bean code for them look like?

              • 5. Re: Tree ignores componentState and stateAdvisor
                mt le Newbie

                Hi Nick,


                thank you for your post. Glad to hear that it should work with a node based tree too So I won't need to switch to an adapter based tree.


                My componentState looks like this:


                private TreeState treeState;
                    public TreeState getTreeState() {
                        if (this.treeState == null) {
                            return new TreeState();
                        return treeState;
                    public void setTreeState(TreeState treeState) {
                        this.treeState = treeState;


                and my stateAdvisor:


                public Boolean adviseNodeOpened(UITree tree) {
                        if (!PostbackPhaseListener.isPostback()) {
                            Object key = tree.getRowKey();
                            TreeRowKey treeRowKey = (TreeRowKey) key;
                            if (treeRowKey == null || treeRowKey.depth() <= 2) {
                                return Boolean.TRUE;
                        return Boolean.FALSE;
                    public Boolean adviseNodeSelected(UITree tree) {
                        return Boolean.TRUE;


                The PostbackPhaseListener is copied from the richfaces demo too.

                I even tried


                public Boolean adviseNodeOpened(UITree tree) {
                        return Boolean.TRUE;

                so every node should be opened. But nothing happens.