11 Replies Latest reply on Sep 11, 2007 1:38 PM by jbarak

    How to expand a node in tree component

    aliok.tr

      Hi,

      I have a "categories" <rich:tree>. I am able to put nodes in it.

      How can I set some node to selected by default? Or I want to expand one node's path by default.

      How can I do this?

        • 1. Re: How to expand a node in tree component
          • 2. Re: How to expand a node in tree component
            aliok.tr

            Thanks, but no good explanation is written there.

            What I understand from that wikipage is, if I return true from my adviseOpenedFunction, then whole tree will be rendered collapsed.

            Like:

            KategoriBean.java
            ...
            
            public Boolean adviseNodeOpenedMethod(UITree tree){
             return true;
            }
            
            ...
            


            and my tree component is:

            <rich:tree value="#{kategoriBean.kategoriAgaci.data}" var="item"
             nodeFace="#{item.type}" showConnectingLines="false" adviseNodeOpened="#{kategoriBean.adviseNodeOpenedMethod}">
             <rich:treeNode type="kategori" >
             <h:outputText value="#{item.ad}"></h:outputText>
             </rich:treeNode>
             </rich:tree>
            


            • 3. Re: How to expand a node in tree component
              jbuechel

              Did you get to work?
              I don't know how to use this method either..

              On the mentoined wiki page I read the following:

              ...This attribute can be assigned to method binding on any bean that will follow the rules: method must accept parameter org.richfaces.component.UITree and return java.lang.Boolean. That method may use getTreeNode() method to get current Tree Node and that return advise...


              So tried to access the current treenode as following:
              public Boolean adviseNodeOpened(UITree uiTree) {
              
               log.debug("uiTree.getTreeNode(): " + uiTree.getTreeNode());
              
               return Boolean.TRUE;
               }

              Unfortunately the treeNode is always null:
              16:32:45,593 INFO [NodeHandler] uiTree.getTreeNode(): null
              16:32:45,625 INFO [NodeHandler] uiTree.getTreeNode(): null
              16:32:45,640 INFO [NodeHandler] uiTree.getTreeNode(): null


              Any assistance would be very appreciated!

              • 4. Re: How to expand a node in tree component
                aliok.tr

                I couldnt solve it yet.

                I think i will use MyFaces tree2 component..

                • 5. Re: How to expand a node in tree component
                  jbuechel

                  That would be a pity!
                  I'm really fascinated about the new tree capabilities and how easy it works since richfaces 3.1.0! The only bad thing i faced until now, is just this issue..

                  So richfaces guys, give as a hint how we can manage that, please!

                  Kind regards,
                  jonas

                  • 6. Re: How to expand a node in tree component
                    nbelaevski

                     

                    What I understand from that wikipage is, if I return true from my adviseOpenedFunction, then whole tree will be rendered collapsed.

                    actually returning true should switch node to expanded state, false to collapsed, null result leads to no change in node state.

                    The following code:
                    public Boolean adviseNodeOpened(UITree tree) {
                     System.out.println(tree.getTreeNode());
                     return Boolean.TRUE;
                     }
                    
                    outputs bunch of TreeNode instances to console for me. Could you please provide example project demonstrating the issue? You can send it to me: nbelaevski at exadel dot com or create new JIRA issue and attach the project there. Thank you in advance!

                    • 7. Re: How to expand a node in tree component
                      nbelaevski

                      Hello all!

                      One more note: if tree is built using tree model components (treeNodes & recursiveTreeNodes) than instances of org.richfaces.model.TreeNode class are absent and tree component doesn't create any as it doesn't need them, that's the reason getTreeNode() returns null. getRowData() should be used in this case; it returns the current collection element.

                      • 8. Re: How to expand a node in tree component
                        jbuechel

                        Great stuff, Nick!

                        I got it working as i needed. This prints the object resident in the nodes:

                        log.debug("uiTree.getRowData(): " + uiTree.getRowData());


                        I've to say congratulation and a big thank you for your great work.
                        You've enhanced the rich:tree in exactly the direction i need it!

                        Just one more question is outstanding for me: ;-)
                        Will there be the possibility to make
                        setWrappedData(Object data)
                        in SequenceDataModel class able to take a Collection (instead of List) or not only List but also java.util.Set?

                        I'm asking because in my case i get a sorted set from persistence. So until now i have to create a new ArrayList for using it..

                        Jonas


                        • 9. Re: How to expand a node in tree component
                          jbarak

                          Which version of rich tree are you using? I don't see adviseNodeOpened attribute in the tag lib Richfaces-3.0.1.jar

                          Thanks

                          • 10. Re: How to expand a node in tree component
                            jbuechel
                            • 11. Re: How to expand a node in tree component
                              jbarak

                              Thanks a zillion jbuechel !

                              Thanks to the richfaces guys for implementing this.