3 Replies Latest reply on Sep 29, 2015 4:15 AM by michpetrov

    <rich:tree> in richfaces 4

    kkn

      Hi,

       

      Reading the upgrade guide, I have created a new class ExtendedTreeNodeImpl.java which extends TreeNodeImpl.java as below

       

      import org.richfaces.model.TreeNode;

      import org.richfaces.model.TreeNodeImpl;

       

       

      public class TreeNodeImplExtended extends TreeNodeImpl {

           private Object data;

           private TreeNode parent;

           private boolean expanded = false;

       

           public Object getData() {

                return data;

           }

           public void setData(Object data) {

                this.data = data;

           }

             public TreeNode getParent() {

                  return parent;

             }

             public void setParent(TreeNode parent) {

                  this.parent = parent;

             }

             public boolean isExpanded() {

                  return expanded;

             }

             public void setExpanded(boolean expanded) {

                  this.expanded = expanded;

             }

      }

       

      Now, I have a tree with checkboxes for each node. While selecting the checkbox, when I try to save the page, I need to traverse the whole tree to find the selected nodes. However, I am not able to get the children of a node. Previously, in TreeNodeImpl, I saw that we had getChildren method in TreeNodeImpl class. Now, I can see children property in TreeNodeImpl but I am not able to access it in my ExtendedTreeNodeImpl class.

      I need something like node.getChildren().

       

      Can you please help how should I get the children of a node or do I need to override all the methods of TreeNodeImpl.java class?

       

      Thanks!

        • 1. Re: <rich:tree> in richfaces 4
          michpetrov

          There aren't that many methods to choose from, are there? Use getChildrenKeyIterator() and getChild(Object key), if you really need a collection then implement your own method.

          • 2. Re: <rich:tree> in richfaces 4
            kkn

            HI Michal,

             

            Thank you so much for your reply! I have tried couple of ways but I ended up writing my own class ExtendedTreeNodeImpl which would implement TreeNode interface. I have added public method getChildren() as available in previous richfaces 3 version as I need tree children for my existing functionality of traversing the selected node and save only selected nodes.

             

            However, can you please explain why the public method getChildren() was removed from version 4. Is there any reason or maybe disadvantages of having the public method getChildren()?

             

            But after making it work, I see that the tree icons (expand/collapse) are plus and minus signs as below

            t1.png

            However, previously, I was getting arrows as below

             

            t2.png

            I tried setting expandIcon and collapseIcon but that did not work. Can you please help me how can I get the icons shown in the second image?

             

            Thank you!

            • 3. Re: <rich:tree> in richfaces 4
              michpetrov

              I tried setting expandIcon and collapseIcon but that did not work. Can you please help me how can I get the icons shown in the second image?

              Those are not the right attribute names, not even in RichFaces 3, use iconExpanded and iconCollapsed.