0 Replies Latest reply on Jul 10, 2008 3:55 AM by Szczepan Marchewka

    Problem with changeExpandListener...

    Szczepan Marchewka Newbie

      I want to do a tree with dynamic nodes loading, when user expand one of the nodes.

      I create a tree with initial loaded only top nodes of the tree and empty subnodes (top nodes are displayed with icon to expand). When user clicks on the expand icon, empty subnode of the top node is removed from the tree and subnodes are added to the expanded node.

      It works good on the top node, but not on the subnodes (deep in the tree). It looks, like change/expand event is raised only on the top level of the tree, but not on the lower levels.

      Please tell my, why?

      Bean declaration in faces-config.xml:
      ---------------------------------------------
      <managed-bean>
      <managed-bean-name>Test</managed-bean-name>
      <managed-bean-class>bdr.test.Test</managed-bean-class>
      <managed-bean-scope>request</managed-bean-scope>
      </managed-bean>
      ---------------------------------------------

      Java class bdr.test.Test
      ---------------------------------------------
      public class Test implements NodeExpandedListener {
      private HtmlTree tree;
      private TreeNodeImpl model;

      public Test() {
      tree = new HtmlTree();
      initModel();
      }

      public HtmlTree getTree() {
      return tree;
      }

      public void setTree(HtmlTree tree) {
      this.tree = tree;
      }

      public TreeNodeImpl getModel() {
      return model;
      }

      public void setModel(TreeNodeImpl model) {
      this.model = model;
      }

      public void initModel() {
      if (this.model==null) {
      this.model = new TreeNodeImpl();
      for (int i=0;i<10;i++) {
      TreeNodeImpl tmp = new TreeNodeImpl();
      tmp.setData("Node 1-"+i);
      //null node to see expand icon
      TreeNodeImpl nullNode = new TreeNodeImpl();
      nullNode.setData("");
      tmp.addChild("NULL", nullNode);
      this.model.addChild("n1-"+i, tmp);
      }
      }
      }

      public void processExpansion(NodeExpandedEvent evt) throws AbortProcessingException {
      System.out.print("processExpansion: "+evt.toString());
      TreeNode node = this.tree.getTreeNode();
      if (node.getChild("NULL")!=null) {
      node.removeChild("NULL");
      if (node.getParent().equals(model)) {
      //we expand first level
      for (int i=0;i<6;i++) {
      TreeNodeImpl tmp = new TreeNodeImpl();
      tmp.setData("Node 2-"+i);
      node.addChild("n2-"+i, tmp);
      TreeNodeImpl nullNode = new TreeNodeImpl();
      nullNode.setData("");
      tmp.addChild("NULL", nullNode);
      }
      } else if (node.getParent().getParent().equals(model)) {
      //we expand second level
      for (int i=0;i<3;i++) {
      TreeNodeImpl tmp = new TreeNodeImpl();
      tmp.setData("Node 3-"+i);
      node.addChild("n3-"+i, tmp);
      }
      }
      }
      System.out.println(" : "+node.getData());
      }

      }
      -----------------------------------------------

      test.xhtml
      -----------------------------------------------
      <rich:tree binding="#{Test.tree}" value="#{Test.model}" var="item"
      changeExpandListener="#{Test.processExpansion}"
      switchType="ajax">
      <rich:treeNode>
      <h:outputText value="#{item}"/>
      </rich:treeNode>
      </rich:tree>
      -----------------------------------------------

      Change/expand events are raised only on the on the nodes "Node1-*" and not on the nodes "Node2-*".

      Why?

      Thanks for help.

      SM