6 Replies Latest reply on Mar 23, 2009 2:34 PM by Nick Belaevski

    Custom Richfaces Tree

    Mikael Aksamit Newbie

      Hi,

      I have been looking at the default tree model examples at http://jsfunit.demo.jboss.com/jboss-jsfunit-examples-richfaces/richfaces/tree.jsf?tab=model&cid=2349046 and playing with simple customization such as changing icons.

      However I wonder if it is possible to mix in other elements on the tree nodes than the default text elements.

      E.g.

      First level of nodes are rows with 5 columns of data.
      When I expand any of these rows I want to get a first row that is a larger panel with an image and data, and following rows at this level should contain just some row data.

      Hope I was clear enough in what I want to achieve. Basically please let me know if the functionality is even possible to achieve with <rich:tree>. If you happen to know any other nice custom implementations of the <rich:tree> I would be very glad to see them to understand possible limitations.

      Very new at this forum, so hope I didn't misplace this thread.

      // Mike

        • 1. Re: Custom Richfaces Tree
          Mikael Aksamit Newbie

          Hi,

          Have been browsing the forum extensively and found out that a lot of users are experiencing something I am experiencing as well, namely lack of examples showing how to use <rich:tree> in other ways than the "default tree model". Does anyone know of other resources worth reading through?

          Back to my question, can a tree node be any type of element? If yes, could someone please show an easy example to get me started?

          Thanks,

          Mike

          • 2. Re: Custom Richfaces Tree
            Mikael Aksamit Newbie

            Hi,

            I am still struggling with my problem but making some progress. Have come to the conclusion that custom TreeNodes are very possible. One way of accomplishing it seems with the use of different nodeFaces or by the use of <rich:treeNodesAdaptor>.

            I have realised that I would still need a custom TreeNode-implementation to store all needed values. The documentation suggests that it is possible to make a custom TreeNode derived from org.richfaces.model.TreeNodeImpl, however of course no examples are given how the custom treenode could look like, I have not been able to find any complete examples using custom TreeNodes.

            Is it only me? I am very new to RichFaces, maybe taking the struggle with <rich:tree> is not the best option based on my knowledge about RichFaces. However I feel the problem is lack of documentation, so far I have been using the resources found at http://www.jboss.org/file-access/default/members/jbossrichfaces/freezone/docs/devguide/en/html/tree.html and the livedemo page. If I have missed other valuable resources, please let me know.

            // Mike

            • 3. Re: Custom Richfaces Tree
              Mikael Aksamit Newbie

              Hi,

              Unfortunately I don't seem to get any further with my problem. I have read all available information looking for hints and tips but it is really hard to understand the complete functionality without any hands on example.

              I have problem creating the custom TreeNode that implements org.richfaces.model.TreeNodeImpl. My main issue is the getData() and setData() methods which i want to override and use my own datacontainer within, however any attempt to do this leaves me with compilation errors, such as:

              Caused by: javax.faces.FacesException: javax.el.PropertyNotFoundException: The class 'webtester.SimpleTreeBean$NodeData' does not have the property 'nodeData'.

              It seems that the object received from getData() should have a recursive reference to any other parents/childrens, this doesn't make sense according to the API found at http://www.jboss.org/file-access/default/members/jbossrichfaces/freezone/docs/apidoc_framework/org/richfaces/model/TreeNode.html

              Well I am clueless and hope someone wiser than me could give me a point in the right direction. Is there really no available example showing how to implement a custom TreeNode?

              Thanks, Mike

              • 4. Re: Custom Richfaces Tree
                Nick Belaevski Master

                Inner classes (e.g. NodeData) should be public and static. It is better not to use inner classes at all.

                • 5. Re: Custom Richfaces Tree
                  Mikael Aksamit Newbie

                  Hi Nbelaevski,

                  Thanks for pointing that out for me. It will surely bring me closer to the solution.

                  I have a small design question and wonder if you could give me comments on this approach.

                  I intend to create a class EventTreeNode that implements org.richfaces.model.TreeNode

                  For each node I need to store 3 values (business data), my intended approach is to use another class "NodeData" that hold these values. So each EventTreeNode will hold a reference to a NodeData object, that is get/set with the these overided methods:

                  public Object getData() {
                  return this.nodeData();
                  }

                  public void setData(Object arg0) {
                  this.setNodeData(arg0);
                  }

                  I don't know if what I am doing is really necessary, maybe a better approach would be to store the business data as variables inside the EventTreeNode. Would be very grateful for a comment regarding my approach.

                  I also wonder if I am free to put variables that defines the "type" of the TreeNode freely anywhere or if they should be extracted by specific setter/getters.

                  Thanks for your patience, Mike

                  • 6. Re: Custom Richfaces Tree
                    Nick Belaevski Master

                    Mike,

                    You can use any approach you like: either separate values into model object or add attributes into UI class; use what's more appropriate from the site of backend.

                    TreeNode doesn't have type attribute itself and that's done intentionally. You can use any expression for "nodeFace" attribute, e.g.

                    nodeFace="#{treeNodeVar instanceof SimpleNode ? 'simple' : 'complex'}"