5 Replies Latest reply on Dec 2, 2008 11:17 PM by joblini

    Tree componentState is not working?

    joblini

      Hello,

      I am attempting to save tree state (expanded nodes) across requests. As per the documentation, I am using the componentState attribute to bind the state to a backing bean. http://www.jboss.org/file-access/default/members/jbossrichfaces/freezone/docs/devguide/en/html/tree.html

      componentState javax.el.ValueExpression (must evaluate to org.ajax4jsf.model.DataComponentState)


      The problem is that setComponentState is only called once, when initializing the tree, and never after that, although getComponentState is called multiple times.

      When should setComponentState be called? After a post-back? After every change in the table's state?. I am stepping through the UITreee and UIDataAdapter classes in Debug, any hints or information would be greatly appreciated!

      Here is my code:

      <rich:tree style="width:300px" switchType="ajax" componentState="#{treeController.componentState}">
      


      @Name("treeController")
      @Scope(ScopeType.CONVERSATION)
      public class TreeController extends EntityController
      {
       private static final long serialVersionUID = 1L;
      
       protected DataComponentState componentState;
      // protected TreeState componentState;
      
       public DataComponentState getComponentState() {
       return componentState;
       }
      
       public void setComponentState(DataComponentState componentState) {
       this.componentState = componentState;
       }
      
      }


      I have read all posts on this subject that I could find. It appears that in the past this was accomplished using TreeState rather than DataComponentState. http://www.jboss.com/index.html?module=bb&op=viewtopic&t=119410



        • 1. Re: Tree componentState is not working?
          nbelaevski

          Hi,

          Algorithm is the same as used for component binding: if getter doesn't return not-null result then state is created and setter is called.

          • 2. Re: Tree componentState is not working?
            joblini

            Hi,

            "nbelaevski" wrote:
            Algorithm is the same as used for component binding: if getter doesn't return not-null result then state is created and setter is called.


            OK, thanks, that explains the one and only call to setComponentState which I observerd in Debug.

            The problem is that there are no further calls to setComponentState. The state of the Tree, that is, the expanded nodes, are never saved.

            I also tested with RF 3.3.0 Beta, the signature has changed to use TreeState instead of DataComponentState, but the same problem exists, the state of the Tree is not saved.




            • 3. Re: Tree componentState is not working?
              joblini

              Hello,

              I have examined, in debug, the UITreee and UIDataAdapter classes, and I do not see any calls to setComponent other than the call from getComponent performed during initialisation of the tree's state.

              It seems that the tree state is never saved by calling setComponent.

              Is this a known problem?

              Thank you.

              • 4. Re: Tree componentState is not working?
                nbelaevski

                Hi,

                This is working perfectly for me using session-scoped variable:

                <h:form>
                 <h:outputLink value="/demo/faces/pages/forum13.jspx">Redirect</h:outputLink>
                 <rich:tree value="#{treeAction.tree}" var="node" componentState="#{treeAction.state}">
                 <rich:treeNode>
                 <h:outputText value="#{node}" />
                 </rich:treeNode>
                
                 </rich:tree>
                
                </h:form>


                Btw, I've used java.lang.Object as state type in order not to depend on its real type.

                • 5. Re: Tree componentState is not working?
                  joblini

                  Thank you, you are right, it does work perfectly. I did not realize that the state was being updated in the calls to getComponentState. (I was expecting setComponentState to be called). Thanks again!