3 Replies Latest reply on Jun 21, 2007 5:51 AM by alexanderbelov

    Richfaces tree and conversation switching

      When switching between coversations in conversation list my rich tree component,who has a switch type ajax, loses it's previous state. But when submiting a page in that conversation, richfaces tree saves its state and stays in previous condition!!

      First picture link

      Second picture link

      Third picture link

        • 1. Re: Richfaces tree and conversation switching

          I have the same problem, if I don't use binding of the tree in session managed-bean.

          • 2. Re: Richfaces tree and conversation switching

            I can save state of the tree on this way:

            >>In jsp my tree component look's like this:

            <r:tree id="drvo" switchType="ajax" style="width:300px"
            dragType="test"
            value="#{richKatalog.data}" var="item" nodeFace="#{item.type}"
            binding="#{tree}"
            preserveDataInRequest="true"
            changeExpandListener="#{katalogTest.onExpand}"
            immediate="false">

            >>My bean look's like this:

            package orka.test;

            import java.io.IOException;

            import javax.faces.component.UIComponent;
            import javax.faces.event.FacesEvent;

            import org.jboss.seam.ScopeType;
            import org.jboss.seam.annotations.In;
            import org.jboss.seam.annotations.Name;
            import org.jboss.seam.annotations.Out;
            import org.jboss.seam.annotations.Scope;
            import org.richfaces.component.UITree;
            import org.richfaces.component.UITreeNode;
            import org.richfaces.component.events.NodeExpandedEvent;
            import org.richfaces.component.state.TreeState;

            @Name("katalogTest")
            @Scope(ScopeType.CONVERSATION)
            public class KatalogTest{

            @In @Out
            private UITree tree;

            TreeState state;

            public void ispisi(){
            System.err.println(tree);
            System.err.println("promjenio");
            System.err.println(tree.getDragType());

            try {
            tree.queueExpandAll();
            } catch (IOException e) {
            e.printStackTrace();
            }
            }


            public void onExpand(NodeExpandedEvent event){
            // UITree drvo = getTree(event);
            state=(TreeState) tree.getComponentState();
            // System.out.println("Node " + (drvo.isExpanded() ? "expanded" : "collapsed") + " " + drvo.getRowKey());
            }

            public void restoreState(){
            System.err.println("Usao u restore state");
            tree.setComponentState(state);
            }

            private UITree getTree(FacesEvent event){
            UIComponent component = event.getComponent();
            if(component instanceof UITree){
            System.err.println("uitree");
            return (UITree)component;
            }
            if(component instanceof UITreeNode){
            System.err.println("uitreenode");
            return (UITree)component.getParent();
            }else
            return null;
            }
            }

            This saves state of the tree on every expand and collapse of the node, and through the method called restore state i can restore my previous state of tree.
            But there comes again one problem...Can I somehow call a method from a pageflow...I need this because when coming back to that conversation in conversation list previous state should be restored, that is the best way because i don't want to push the button to call the action method restore state...

            • 3. Re: Richfaces tree and conversation switching

              It seems there is no API to control tree state. The problem is in TreeState class. It is not serializable and cannot be saved in session.

              If you save you bean in request scope, the state will be lost. You can save your bean in session scope and call restoreState() method in getTree() method, for example.