10 Replies Latest reply on Jul 4, 2007 9:23 AM by nbelaevski

    rich:tree not staying expanded

    ccrouch

      Apologies for the noob question...

      I'm having problems with rich:tree not staying expanded after I've clicked on a link from one of its nodes. I'm sure its something very obvious. What am I missing?

      I've taken the example from http://livedemo.exadel.com/richfaces-demo/richfaces/tree.jsf and just tweaked it to have links to some of my seam actions on some of the nodes:

      <rich:tree
       style="width:300px"
       value="#{navigationAction.treeNode}"
       var="item"
       nodeFace="#{item.type}"
       switchType="ajax">
      
       <rich:treeNode type="artist">
       <h:commandLink action="#{summaryAction.view}">
       <f:param name="path" value="/resources/type2"/>
       <h:outputText value="#{item.name}" />
       </h:commandLink>
       </rich:treeNode>
       <rich:treeNode type="album">
       <h:commandLink action="#{summaryAction.view}">
       <f:param name="path" value="/resources/type1"/>
       <h:outputText value="#{item.title}" />
       </h:commandLink>
       </rich:treeNode>
       <rich:treeNode type="song">
       <h:outputText value="#{item.title}" />
       </rich:treeNode>
       </rich:tree>


      The tree is wrapped in a facelets <ui:composition> tag and included in each page via a <ui:include> in the main layout.xhtml.
      The value for the tree is stored in the user's session. In fact navigationAction above is Seam component, @Scope(ScopeType.SESSION). with

      private TreeNode library;
       public TreeNode getTreeNode()
       {
       if (library == null)
       {
       library = new Library();
       }
       return library;
       }


      I can see through the debugger that only once instance of Library is getting created per session.

      The tree renders fine when first viewing a page, you can expand it etc no problem. But when you click on one of the nodes and render a new page the tree collapses to its original state?? I would like to remain expanded.

      Setup:
      JBoss 4.0.5
      JSF 1.2_04 RI
      Seam 1.1.6.GA
      Facelets 1.1.12
      Ajax4jsf 1.1.1-SNAPSHOT (4/26)
      Richfaces 3.0.1.-SNAPSHOT (4/26)

        • 1. Re: rich:tree not staying expanded
          nbelaevski

          Hello!

          Are you using redirect in action?

          • 2. Re: rich:tree not staying expanded
            ccrouch

             

            "nbelaevski" wrote:
            Are you using redirect in action?


            Excellent question. In the links I'm currently using from the tree we're actually not using redirects, i.e.

            <faces-config>
             <navigation-rule>
             <navigation-case>
             <from-action>#{summaryAction.view}</from-action>
             <from-outcome>table</from-outcome>
             <to-view-id>/categorySummary.xhtml</to-view-id>
             </navigation-case>
             <navigation-case>
             <from-action>#{summaryAction.view}</from-action>
             <from-outcome>root</from-outcome>
             <to-view-id>/rootSummary.xhtml</to-view-id>
             </navigation-case>


            However some of the links on other pages will use redirects.
            Is the tree component not expected to stay expanded across redirects?

            Thanks

            • 3. Re: rich:tree not staying expanded
              nbelaevski

              Yes, redirects loose components state, so tree component cannot get it back. We're planning to introduce state serialization to model in the future versions. You can also try to set state saving method to server.

              • 4. Re: rich:tree not staying expanded
                ccrouch

                So I'm still having problems with this...

                The link in the tree node looks like

                <rich:treeNode type="blah">
                 <h:commandLink action="#{summaryAction.view2}">#{item.name}
                 <f:param name="path2" value="#{item.id}"/>
                 </h:commandLink>
                 </rich:treeNode>


                In my view2() method I pull the parameter path2 out of the request and determine the from-outcome

                In navigation.xml I have

                <navigation-case>
                 <from-action>#{summaryAction.view2}</from-action>
                 <from-outcome>resInstance</from-outcome>
                 <to-view-id>/resInstance.xhtml</to-view-id>
                 </navigation-case>


                In web.xml I'm using server side state saving...

                <context-param>
                 <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
                 <param-value>server</param-value>
                 </context-param>
                


                However when I click on the link in the nav, when the page is rendered the nav goes back to its unexpanded state. I've tried switchType of client and ajax and get the same results.
                BTW I've also upgraded Seam to 1.2.1.GA and there was no difference.

                Any suggestions?

                Thanks

                • 5. Re: rich:tree not staying expanded
                  ccrouch

                   

                  "nbelaevski" wrote:
                  We're planning to introduce state serialization to model in the future versions.


                  Is there a jira for this work? If not, would you like me to create one?

                  http://jira.jboss.com/jira/browse/RF-85 [Tree: component needs to save state in "client" mode], looks kind of related but the problem does not appear to be associated with just "client" mode, since I'm seeing it with "ajax" too.

                  Thanks

                  • 6. Re: rich:tree not staying expanded
                    ccrouch

                    Does anyone know of any examples of using the rich:tree component which include either h:commandLink's or Seam's s:link within the rich:treeNodes. The online example:
                    http://livedemo.exadel.com/richfaces-demo/richfaces/tree.jsf?c=tree

                    doesn't and neither does the tree-demo:

                    http://maven.exadel.com/org/richfaces/tree-demo/

                    Thanks

                    • 7. Re: rich:tree not staying expanded
                      stu2

                      Any more examples or documentation for trees in the works?

                      Looking through the forum there's countless people all asking the same questions, often with no resolution..

                      The only docs for tree stuff that I'm aware of are http://labs.jboss.com/file-access/default/members/jbossrichfaces/freezone/docs/devguide/index.html , and it goes into very light detail.

                      • 8. Re: rich:tree not staying expanded
                        nbelaevski

                        Hello all!

                        I've investigated the case. Neither JSF nor JSF + Facelets can't handle the described case properly when action outcome is not null. JSF just drop component tree state, thus causing the problem described. To see the problem reproducing with standard components, place <h:inputText value="1">, change value to 0 and then submit action. If action has outcome bringing us back to that page, you'll see "1" value, otherwise "0".

                        Tree component needs a little refactoring at the present time to be able to bind its internal state to model elements, so I can suggest a workaround: bind the whole component to some request-scoped stuff. It should work because component will be stored in request scope on the decode phase and then reused on encode phase, thus saving its internal state.

                        • 9. Re: rich:tree not staying expanded
                          ccrouch

                           

                          "nbelaevski" wrote:

                          Tree component needs a little refactoring at the present time to be able to bind its internal state to model elements, so I can suggest a workaround: bind the whole component to some request-scoped stuff. It should work because component will be stored in request scope on the decode phase and then reused on encode phase, thus saving its internal state.


                          I tried creating the HtmlTree component programmatically
                          HtmlTree navTree = (HtmlTree) getApplication().createComponent(HtmlTree.COMPONENT_TYPE);
                          ...


                          and then binding it into the xhtml page

                          <rich:tree binding="#{navTree}" />


                          I'm building this in Seam so I tried giving the tree component a scope of ScopeType.EVENT (equivalent to request). However I'm still seeing the tree collapse if I click on a node which eventually renders a different .xhtml page. I tried putting the component in ScopeType.SESSION and got the same result.

                          Am I doing something wrong?

                          Could you provide an example showing the workaround you suggested?

                          Thanks

                          • 10. Re: rich:tree not staying expanded
                            nbelaevski

                            Charles,

                            I haven't tried to create component programmatically, but that should not affect component behaviour. Here is the sample: https://svn.jboss.org/repos/richfaces/branches/3.0.2/richfaces-samples/tree-demo I've used when testing the issue. Just add action component and try if the component saves its state.