11 Replies Latest reply on Jun 10, 2015 12:34 PM by kk n

    richfaces 4 <rich:tree> simple usage

    Dosi Bingov Newbie

      I am trying to implement the simple example like in the documentation of richafes 4 http://docs.jboss.org/richfaces/latest_4_0_X/Component_Reference/en-US/html/chap-Component_Reference-Trees.html but it does not work at all. When I try to creatate stationRoot generic Eclipse says that it is not defined like generic.

      private TreeNodeImpl<String> stationRoot = new TreeNodeImpl<String>();//does not work
      

       

      I was thinking maybe it is not genereic but the methode setData does not exist too.

       

      stationRoot.setData("KickRadio");
      

       

      How can I set the name of tree node ? I am using version v.4.1.0-SNAPSHOT SVN r.22411 from the SVN server

      Do I do something wrong or the documentation is wrong ?

        • 1. richfaces 4 <rich:tree> simple usage
          Ilya Shaikovsky Master

          doh.. really that was missed during documentation review. TreeNode interface and TreeNodeImpl class not generic actually. Why was that done? Because we removed abstract field for node data from the default implementation. We decided to keep noly TreeNode interface logic default impl there. so it has no T field for user data anymore.

           

          How to use it now? Still pretty simple. Just create your own class for TreeNode which will extend TreeNodeImpl and add only the data fields you need there with accessor methods. Then you will keep it just as simple as required according your data objects and will get all the node functionlity implemented by default.

          • 3. richfaces 4 <rich:tree> simple usage
            Dosi Bingov Newbie

            Thanks for your fast response. I hope the documentaton will be corrected so other poeple will benefit from this beautiful rich component dynamically. It is still not very clear how to set the name of the node but I will give it a try.

            • 4. Re: richfaces 4 <rich:tree> simple usage
              Dosi Bingov Newbie

              I succeed creating the basic example of rich:tree. The only remark I have is that sometimes the tree nodes look like they are collapsible even if they don't have subnodes

               

              Bellow is my code:

               

              import org.richfaces.model.TreeNodeImpl;
              
              public class OptionTreeNode extends TreeNodeImpl {
                  private String name;
              
                  public String getName() {
                      return name;
                  }
              
                  public void setName(String name) {
                      this.name = name;
                  }
              
                  public String toString() {
                      return this.name;
                  }
              
              }
              

               

              I needed to override toString() method because the reference of the class was displayed

               

              public class OptionTree implements Serializable {
              
                  private static final long serialVersionUID = 1L;
              
                  private OptionTreeNode stationRoot = new OptionTreeNode();
              
                  private OptionTreeNode stationNodes = new OptionTreeNode();
              
                  public OptionTreeNode getStationNodes() {
                      return stationNodes;
                  }
              
                  private String[] kickRadioFeed = { "Hall & Oates - Kiss On My List",
              
                  "David Bowie - Let's Dance",
              
                  "Lyn Collins - Think (About It)",
              
                  "Kim Carnes - Bette Davis Eyes",
              
                  "KC & the Sunshine Band - Give It Up" };
              
              
                  public OptionTree() {
                      initRichFacesTree();
                  }
              
                  private void initRichFacesTree() {
                      stationRoot.setName("root");
                      stationNodes.addChild(0, stationRoot);
              
                      for (int i = 0; i < kickRadioFeed.length; i++) {
                          OptionTreeNode child = new OptionTreeNode();
                          child.setName(kickRadioFeed[i]);
                          stationRoot.addChild(i, child);
                      }
              
                  }
              }
              

               

              And my xhtml code

               

              <rich:tree value="#{optionTree.getStationNodes()}" var="station" toggleType="client" >
              
                 <rich:treeNode >
              
                    <h:outputText value="#{station}" />
              
                 </rich:treeNode>
              
              </rich:tree>
              

               

              treenodes.jpg

              The subnodes does not look like in the documentation.

              • 5. Re: richfaces 4 <rich:tree> simple usage
                Ilya Shaikovsky Master

                if you will review default impl org.richfaces.model.TreeNodeImpl you will see that isLeaf returns the property which is getting defined only in constructor and not looking the child component list size. default converter initializes the flag as true.  and the tree makes decision about if the node is leaf accordgin to that.

                 

                That's done just in order to work with data in more "lazy" manner but require some actions from you. you could:

                create a constructor with leaf boolean flag and call it in case of crteating leaf with true value. That constructor should call supor(leafFlag) before setting the other fields. And it should start work fine in your case.

                 

                or you could just overried isLeaf method simply checking if you have some nodes in child collection.

                • 6. Re: richfaces 4 <rich:tree> simple usage
                  Dosi Bingov Newbie

                  Thanks !  I will make it like it should be

                  • 7. Re: richfaces 4 <rich:tree> simple usage
                    William Abbott Newbie

                    This documentation 'bug' has kind of been around for almost a year now.

                    • 8. Re: richfaces 4 <rich:tree> simple usage
                      Ferdinan Tolentino Newbie

                      Hi

                      How did you resolve the missing setData() and getParent() method in TreeNodeImpl in RF4?

                      Thanks!

                      • 9. Re: richfaces 4 <rich:tree> simple usage
                        kk n Newbie

                        Hi,

                         

                        Can you please explain the significance of keysList in TreeNodeImpl class.

                         

                        Thank you!

                        • 10. Re: richfaces 4 <rich:tree> simple usage
                          Michal Petrov Master

                          The keysList is used to create an iterator (and to keep the children ordered). What is unclear to you? I have to assume you've seen the code and where the variable is used. (And please don't revive old threads, chances are that people who created them are no longer around)

                          • 11. Re: richfaces 4 <rich:tree> simple usage
                            kk n Newbie

                            Apologies for posting on old thread, I was not aware of that

                             

                            Thank you for the reply! Certainly, I saw the class but just wanted to make sure that I am using it the correct way. Now I got the concept. Thank you again!