1 Reply Latest reply on Jul 11, 2007 11:29 AM by Novin

    rich:tree Childnode didn't rendered

    Novin Newbie

      Hi Friends,

      I am facing customsed Treenode implementation problem.

      When user select groupname-node I add child nodes(groupnumber-node) selected node using nodeSelectListener event method.


      Problem1: The childnode adding code is working fine. But when the response to the event is generated on JSP page the node which we have clicked earlier didn't get any child node(appeneded.)

      Problem2: I want only the lasly selected node and its child nodes to be rerendered in the response not the whole tree.

      for that i m playing with this code but i m not sure this will work or not(it is not throwing any exception and running fine)

      //which is current selected node 's key
      ListRowKey key = (ListRowKey)getTree(event).getRowKey();
      if (keys == null)
      {
      keys = new HashSet();
      tree.setAjaxKeys(keys);
      }
      FacesContext fctx = FacesContext.getCurrentInstance();
      AjaxContext ajaxCtx = AjaxContext.getCurrentInstance();

      UITree tree = getTree(event);
      Set keys = tree.getAjaxKeys();
      keys.add(key);
      tree.setRowKey(key);
      ajaxCtx.addComponentToAjaxRender(tree.getParent(), tree.getClientId(fctx));
      tree.setRowKey(key);




      My tree contain max 4 type of node

      "root-node"
      ............groupname-node
      ------------ groupnumber-node
      -------------account-node

      For all the four type of node do I need to put 4 treenode in jsp page for every type?


      JSP file tree code:

      <h:panelGroup id="TreePanel">
      <rich:tree style="width:300px" value="#{accountTreeBean.treeData}" var="item"
      ajaxSubmitSelection="true" switchType="ajax"
      nodeFace="#{accountTreeBean.treeData.type}"
      >
      <rich:treeNode type="root-node" nodeSelectListener="#{accountTreeBean.getGrpNumbersForSelectedGrpName}">
      <h:outputText value="#{item.description}" />
      </rich:treeNode>

      <rich:treeNode type="groupname-node">
      <h:outputText value="#{item.description}" />
      </rich:treeNode>
      <rich:treeNode type="groupnumber-node">
      <h:outputText value="#{item.description}" />
      </rich:treeNode>
      <rich:treeNode type="account-node">
      <h:outputText value="#{item.description}" />
      </rich:treeNode>
      </rich:tree>
      </h:panelGroup>



      BaseTreeNode

      public class BaseTreeNode implements TreeNode{

      private String identifier;
      private String description;
      private String type;

      private TreeNode parent;
      private Map childrenMap = new LinkedHashMap();


      public BaseTreeNode() { System.out.println("constructor BaseTreeNode 1");}

      public BaseTreeNode(String type, String identifier, String description)
      {
      System.out.println("constructor BaseTreeNode 2 type:"+type);
      this.type = type;
      this.identifier = identifier;
      this.description = description;

      }

      public BaseTreeNode(String type, String identifier, String description, boolean leaf)
      {
      System.out.println("constructor BaseTreeNode 3");
      this.type = type;
      this.identifier = identifier;
      this.description = description;
      }

      public TreeNode getData() {
      System.out.println("getData() BaseTreeNode.");
      return this;
      }


      public TreeNode getChild(Object identifier) {
      if(type.equalsIgnoreCase("account-node"))
      throw new UnsupportedOperationException("account-node do not have children");
      return (TreeNode) childrenMap.get(identifier);
      }

      public void addChild(Object identifier, TreeNode child) {
      if(type.equalsIgnoreCase("account-node"))
      throw new UnsupportedOperationException("account-node do not have children");

      child.setParent(this);
      childrenMap.put(identifier, child);
      }

      public TreeNode getParent() {
      System.out.println("**Enter getParent identifier:" + identifier + " description:"+ description + " type:"+ type);
      if(type.equalsIgnoreCase("root-node"))
      return null;
      else
      return parent;
      }

      public Iterator getChildren() {
      //TODO: Fix me!
      if(type.equalsIgnoreCase("account-node"))
      return new ArrayList().iterator(); // work around limitation for TreeNode
      else
      return childrenMap.entrySet().iterator();
      }

      public void removeChild(Object identifier) {
      if(type.equalsIgnoreCase("account-node"))
      throw new UnsupportedOperationException("account-node do not have children");

      TreeNode treeNode = (TreeNode) childrenMap.remove(identifier);
      if (treeNode != null) {
      treeNode.setParent(null);
      }
      }

      public void setData(Object data) {
      }

      public void setParent(TreeNode parent) {
      if(!type.equalsIgnoreCase("root-node"))
      this.parent = parent;
      }

      public boolean isLeaf() {
      return childrenMap.isEmpty();
      }

      /**
      * @see org.apache.myfaces.custom.tree2.TreeNode#getType()
      */
      public String getType()
      {
      return this.type;
      }

      /**
      * @see org.apache.myfaces.custom.tree2.TreeNode#setType(java.lang.String)
      */
      public void setType(String type)
      {
      this.type = type;
      }

      /**
      * @see org.apache.myfaces.custom.tree2.TreeNode#getDescription()
      */
      public String getDescription()
      {
      return this.description;
      }

      /**
      * @see org.apache.myfaces.custom.tree2.TreeNode#setDescription(java.lang.String)
      */
      public void setDescription(String description) {
      this.description = description;
      }

      /**
      * @see org.apache.myfaces.custom.tree2.TreeNode#setIdentifier(java.lang.String)
      */
      public void setIdentifier(String identifier) {
      this.identifier = identifier;
      }

      /**
      * @see org.apache.myfaces.custom.tree2.TreeNode#getIdentifier()
      */
      public String getIdentifier()
      {
      return this.identifier;
      }
      }



        • 1. Re: rich:tree Childnode didn't rendered
          Novin Newbie

          Hi Friends,

          Seems like the my tree is working fine.

          Bcas I didn't implemented it properly.

          I have now added following member variable and the getter setters to the bean which contains the root node

          private String pathToExpand;
          private String expandPath;
          private UITree tree;

          Thanks
          Novin