6 Replies Latest reply on Jul 13, 2009 7:25 AM by brian13

    How to collapse rich:tree to its root nodes from a Bean

    brian13

      Hello,

      How can I associate a CommandLink with a rich:tree whose Bean action when activated
      will collapse the tree to its root nodes ? I would like to implement the action to collapse
      the tree preferably in the Java Bean as Java code.

      Thanks for your assistance in advance...
      Regards,
      -- Brian

        • 1. Re: How to collapse rich:tree to its root nodes from a Bean
          nbelaevski

          Hi Brian,

          Use org.richfaces.component.UITree.queueCollapseAll() method.

          • 2. Re: How to collapse rich:tree to its root nodes from a Bean
            brian13

            Hi Nick,

            I have tried using this method but it does not seem to work... are there any other methods that need to be used along with it ?

            Thanks,
            -- Brian

            • 3. Re: How to collapse rich:tree to its root nodes from a Bean
              nbelaevski

              No, how does you call it?

              • 4. Re: How to collapse rich:tree to its root nodes from a Bean
                brian13

                Hi Nick,

                The queueCollapseAll() seems to work if called within the context of a Tree, but I would
                Like to collapse the tree externally from a commandLink or commandButton by passing
                a link to the UItree obtained via one of the listeners in the tree and call this method from
                the action externally ... this does not seem to work. Calling the method within the tree
                works.

                Thanks,
                --Brian

                • 5. Re: How to collapse rich:tree to its root nodes from a Bean
                  ilya_shaikovsky

                  sorry but can't confirm using simple test-case

                  <h:form id="form">
                   <rich:tree style="width:300px" value="#{library.data}" var="item" nodeFace="#{item.type}" id="tree">
                   <rich:treeNode type="artist" iconLeaf="/images/tree/singer.gif" icon="/images/tree/singer.gif">
                   <h:outputText value="#{item.name}" />
                   </rich:treeNode>
                   <rich:treeNode type="album" iconLeaf="/images/tree/disc.gif" icon="/images/tree/disc.gif">
                   <h:outputText value="#{item.title}" />
                   </rich:treeNode>
                   <rich:treeNode type="song" iconLeaf="/images/tree/song.gif" icon="/images/tree/song.gif">
                   <h:outputText value="#{item.title}" />
                   </rich:treeNode>
                   </rich:tree>
                   <a4j:commandLink actionListener="#{userBean.collapseTreeById}" value="collapse" reRender="tree">
                   <f:param value="form:tree" name="treeId"/>
                   </a4j:commandLink>
                   </h:form>

                  public void collapseTreeById(ActionEvent event) throws IOException {
                   String treeId = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("treeId");
                   UIViewRoot viewRoot = FacesContext.getCurrentInstance().getViewRoot();
                   UITree tree = (UITree)viewRoot.findComponent(treeId);
                   tree.queueCollapseAll();
                   }


                  • 6. Re: How to collapse rich:tree to its root nodes from a Bean
                    brian13

                    Hello Ilya,
                    Thanks for the suggestion, but the problem we are having is that the tree is in a different
                    subview and the command link is in a different subview, the below suggested approch
                    does not seem to work
                    here is how the setup is:
                    <subview id=subview1>
                    <h:form id="form">
                    <rich:tree style="width:300px" value="#{library.data}" var="item" nodeFace="#{item.type}" id="tree">
                    <rich:treeNode type="artist" iconLeaf="/images/tree/singer.gif" icon="/images/tree/singer.gif">
                    <h:outputText value="#{item.name}" />
                    </rich:treeNode>
                    <rich:treeNode type="album" iconLeaf="/images/tree/disc.gif" icon="/images/tree/disc.gif">
                    <h:outputText value="#{item.title}" />
                    </rich:treeNode>
                    <rich:treeNode type="song" iconLeaf="/images/tree/song.gif" icon="/images/tree/song.gif">
                    <h:outputText value="#{item.title}" />
                    </rich:treeNode>
                    </rich:tree>
                    </h:form>

                    <subview id=subview2>
                    <h:form id=form2>
                    <a4j:commandLink actionListener="#{userBean.collapseTreeById}" value="collapse" reRender="tree">
                    <f:param value="form:tree" name="treeId"/>
                    </a4j:commandLink>
                    </h:form>

                    What would be the appropriate collapseTreeById method in such a case ?

                    Thanks,
                    -- Brian