2 Replies Latest reply on Jul 3, 2009 12:38 AM by stevesobol

    Weirdness with rich:tree

    stevesobol

      I have an interesting situation where, under certain conditions, I can't expand a tree by clicking on it.

      The XHTML:

      <html xmlns="http://www.w3.org/1999/xhtml"
       xmlns:h="http://java.sun.com/jsf/html"
       xmlns:f="http://java.sun.com/jsf/core"
       xmlns:a4j="http://richfaces.org/a4j"
       xmlns:ui="http://java.sun.com/jsf/facelets"
       xmlns:rich="http://richfaces.org/rich">
       <a4j:log popup="false" level="WARN" width="500" height="300"/>
       <a4j:form id="folderTreeForm">
       <a4j:commandButton reRender="folderTree" actionListener="#{test.populate1}" value="Pop 1"></a4j:commandButton><br/><br/>
       <a4j:commandButton reRender="folderTree" actionListener="#{test.populate2}" value="Pop 2"></a4j:commandButton><br/><br/>
       <rich:tree immediate="yes" id="folderTree" binding="#{test.tree}" value="#{test.rootNode}"
       var="item" changeExpandListener="#{test.expand}" switchType="ajax" ajaxSubmitSelection="true">
       <rich:treeNode>#{item.value}</rich:treeNode>
       </rich:tree>
      
       </a4j:form>
      
      </html>
      


      The backing bean and a relevant snippet of my Faces config:
       <managed-bean>
       <managed-bean-name>test</managed-bean-name>
       <managed-bean-class>test.Test</managed-bean-class>
       <managed-bean-scope>request</managed-bean-scope>
       </managed-bean>
      


      package test;
      
      import javax.faces.event.ActionEvent;
      
      import org.richfaces.component.html.HtmlTree;
      import org.richfaces.event.NodeExpandedEvent;
      import org.richfaces.model.TreeNodeImpl;
      
      public class Test {
      
       private TreeNodeImpl<MyNode> rootNode = null;
       private HtmlTree tree = new HtmlTree();
      
       public TreeNodeImpl<MyNode> getRootNode() {
       return rootNode;
       }
      
       public void setRootNode(TreeNodeImpl<MyNode> rootNode) {
       this.rootNode = rootNode;
       }
      
       public HtmlTree getTree() {
       return tree;
       }
      
       public void setTree(HtmlTree tree) {
       this.tree = tree;
       }
      
       public void populate1(ActionEvent evt) {
       TreeNodeImpl<MyNode> first = newNode("1");
       rootNode=newNode("0");
      
       rootNode.addChild("1", first);
       first.addChild("2", newNode("2"));
       first.addChild("3", newNode("3"));
       tree.setData(rootNode);
       }
      
       public void populate2(ActionEvent evt) {
       TreeNodeImpl<MyNode> first = newNode("4");
       rootNode=newNode("0");
      
       rootNode.addChild("4", first);
       first.addChild("5", newNode("6"));
       first.addChild("6", newNode("6"));
       tree.setData(rootNode);
       }
      
       public TreeNodeImpl<MyNode> newNode(String s) {
       TreeNodeImpl<MyNode> temp = new TreeNodeImpl<MyNode>();
       temp.setData(new MyNode(s));
       return temp;
       }
      
       public void expand(NodeExpandedEvent evt) {
       System.out.println("expand");
       }
      }
      


      And finally, MyNode:
      package test;
      
      import org.richfaces.model.TreeNodeImpl;
      
      public class MyNode extends TreeNodeImpl<String> {
      
       public static final long serialVersionUID=0L;
      
       String value=null;
      
       public MyNode(String value) {
       this.value = value;
       }
      
       public String getValue() {
       return value;
       }
      
       public void setValue(String value) {
       this.value = value;
       }
      
      }
      


      If I populate the tree in response to a button click -- either using action=whatever or, in this case, using an ActionListener -- the tree will be redrawn, but if I click on the arrow to the left of the root node, nothing happens.

      In Firefox 3.0.11, running on Windows Vista Ultimate SP1, I get the warning:

      warn[13:35:44,048]: No information in response about elements to replace

      In IE 8, running on the same computer, I get an error instead:

      error[13:37:29,154]: . Error message: Invalid argument.

      If I populate the tree in my backing bean's constructor or a method annotated as @PostConstruct, the tree works properly.

      I'm new to RichFaces and I figure I may be doing something wrong.

      Thanks in advance for any help you can offer.





        • 1. Re: Weirdness with rich:tree
          stevesobol

          I noticed something... this may not be the cause of the problem, but instead of

           TreeNodeImpl<MyNode> temp = new TreeNodeImpl<MyNode>();
          


          shouldn't I be doing this?

           MyNode temp = new MyNode();
          



          • 2. Re: Weirdness with rich:tree
            stevesobol

            OK, I solved the problem.

            My code wasn't the problem.

            The problem was that the backing bean was in request scope. When placed in session scope, everything worked.

            But, since I wanted to keep the bean in request scope, the ultimate solution was the addition of:

            <a4j:keepAlive beanName="test"/>