10 Replies Latest reply on Nov 6, 2007 9:43 PM by jvinson

    Help with <rich:tree>

      I'm want to put a <rich:tree> on a web page and I'm having trouble figuring out how to do this. The documentation of what the backing bean structure needs to look like is weak. Are there any documents on the web that describe how to do this. A tutorial maybe?

      Thanks.

        • 1. Re: Help with <rich:tree>
          • 2. Re: Help with <rich:tree>
            ccrouch

             

            <rich:tree style="width:300px" value="#{sourceForTree}" var="data" nodeFace="#{data.type}">


            Its pretty intuitive once you know that the value attribute of rich:tree has to point to something that implements org.richfaces.component.TreeNode, #{sourceForTree} above. There won't be anything rendered for that top level TreeNode, only its children, and their children etc, etc.
            Also the property called "data" above will get populated for each child TreeNode with the result of TreeNode.getData(). So you can implement this method to return your TreeNode implementation itself, which is what the underlying Library object does in the example you posted, or have it return a real business object which is associated with that node in the tree and that you want to reference from rich:treeNode e.g.

            <rich:treeNode type="myType">
             <h:outputText value="#{data.myBusinessProperty}"/>
            </rich:treeNode>


            Finally you need to realize the connection between the 'nodeFace' attribute on rich:tree and the 'type' attribute on rich:treeNode. Its pretty simple other than the slightly unintuitive naming. The expression indicated by 'nodeFace' gets evaluated for every child TreeNode, #{data.type} in the example above. Then the component compares the value of the expression with the values of the 'type' attribute on each rich:treeNode component, "myType" above. When it finds a match it uses that rich:treeNode component to render the node.

            HTH

            • 3. Re: Help with <rich:tree>

              I'm a little confused on one thing. The #{data.type} expression; is that the actual root level node type or is just some string value. The example implementation has the backing objects return a String. However, the String matches exactly the classname. Is that intentional or just accidental.

              • 4. Re: Help with <rich:tree>

                To follow up on my last questions. Is the nodeFace and type matching simply a lexical string match or is there some smart object conversion and equality happening behind the scenes.?

                • 5. Re: Help with <rich:tree>
                  ccrouch

                   

                  "c_eric_ray" wrote:
                  I'm a little confused on one thing. The #{data.type} expression; is that the actual root level node type or is just some string value. The example implementation has the backing objects return a String. However, the String matches exactly the classname. Is that intentional or just accidental.


                  Accidental. That expression doesn't have to resolve to a classname.

                  • 6. Re: Help with <rich:tree>
                    ccrouch

                     

                    "c_eric_ray" wrote:
                    To follow up on my last questions. Is the nodeFace and type matching simply a lexical string match or is there some smart object conversion and equality happening behind the scenes.?


                    Sorry, I don't know enough to help you there. All the examples I've seen have the 'type' attribute set to a raw string. But I've seen the nodeFace attribute get quite fancy:

                    nodeFace="#{data.name != 'param-value' ? 'input' : 'text'}"


                    • 7. Re: Help with <rich:tree>

                      Can anyone confirm that Seam and the <rich:tree> component work together. I'm getting very, very strange behavior when using the two. It's like all the child nodes don't exist (even though they do). Does every node have to be a seam component for the tree to work or can just the root node be a seam component?

                      • 8. Re: Help with <rich:tree>
                        ccrouch

                        I'm using Seam and rich:tree and haven't found any particular issues with integrating them. None of the nodes have to be Seam components, all my are plain pojos.

                        • 9. Re: Help with <rich:tree>

                          Sounds good. Thanks for your help. Appears I have a bug in my code.

                          • 10. Re: Help with <rich:tree>
                            jvinson

                            Were you able to get the tree working? Could you post your code so I can see? I'm trying to create a rich:tree just like you were trying to do and any help you could provide would be much appreciated.