10 Replies Latest reply on May 26, 2009 7:31 AM by derkd

    No tree element available ot  row key not set.. while expand

      Hi All ,
      I want to expand a node from out side tree(fpr example data table)
      When i programatically expanding tree node by creating ListRowKey
      I am getting No tree element available ot row key not set..

      But I am able to expnadAll and collapse All....

      Here is sample application(sorry for Typo errors if any, i typed all the conent, I cannot copy the code from my system)..

      I tried the following inputs :

      2
      2:3
      2:3:4



      It seems problem with ListRowKey,

      when i give input 2:3 , when i made debug messages in UITree queueExandMethod,
      getting RowKey as 2_:3(adding _)....

      kindly provide any correct path for the following tree structure..

      A is root node id:2
      B, C are children to A with ids(3,4 respectively)
      D is child of C with id 5...


      Tthanks in advance....






      Page...
      tree.xhtml.....

      <ui:composition xmlns="http://www.w3.org/1999/xhtml"
       xmlns:ui="http://java.sun.com/jsf/facelets"
       xmlns:h="http://java.sun.com/jsf/html"
       xmlns:f="http://java.sun.com/jsf/core"
       xmlns:a4j="http://richfaces.org/a4j"
       xmlns:rich="http://richfaces.org/rich">
       <p>Sample Tree</p><br/>
       <h:form>
       <rich:tree id="myTree"
       toggleOnClick="true"
       switchType="server"
       ajaxSubmitSelection="true"
       value="#{myTreeBean.myTreeData}" var="compRow"
       ajaxSingle="true"
       binding="#{myTreeBean.tree}
       acceptedTypes="anyType"
       iconLeaf="/images/tree/tree.gif"
       icon="/images/tree/tree.gif"
       nodeFace="anyType">
       <rich:treeNode id="tNode" ajaxSingle="true" type="anyType" >
       <h:outputText value="#{compRow}" />
       </rich:treeNode>
       </rich:tree>
      
      
      <a4j:commandLink action="#{myTreeBean.expandAll}" ajaxSingle="true" reRender="myTree">Expand All</a4j:commandLink>
      <br>
       <h:outputText value="Enter the path to expand" />
      <h:inputText value="#{myTreeBean.path}" />
      <a4j:commandButton action="#{myTreeBean.expandPath}" reRender="myTree" value="Submit " />
      
       </h:form>
      </ui:composition>
      
      



      Faces-Config Entry------

      
      <managed-bean>
      <managed-bean-name>myTreeBean</managed-bean-name>
      <managed-bean-class>org.richfaces.MyTreeBean</managed-bean-class>
      <managed-bean-scope>reques t</managed-bean-scope>
      <managed-bean>
      
      




      -------Managed bean Code---------
      
      package org.richfaces;
      import java.io.IOException;
      import javax.faces.FacesException;
      import javax.faces.component.UIComponent;
      import javax.faces.event.FacesEvent;
      import org.richfaces.component.UITree;
      import org.richfaces.component.UITreeNode;
      import org.richfaces.event.NodSelectedEvent;
      import org.richfaces.model.ListRowKey;
      
      public class MyTreeBean{
      UITree tree;
      private String path;
      //---setter and getters.. for path
      //......
      public TreeImpl getMyTreeData(){
      TreeImpl root=new TreeImpl();
      root.setData("Root Node");
      
      TreeImpl nodeA=new TreeImpl();
      nodeA.setCompId(2L);
      nodeA.setData("Company A");
      
      TreeImpl nodeB=new TreeImpl();
      nodeB.setCompId(2L);
      nodeB.setData("Company B");
      
      TreeImpl nodeC=new TreeImpl();
      nodeC.setCompId(2L);
      nodeC.setData("Company C");
      
      
      TreeImpl nodeD=new TreeImpl();
      nodeD.setCompId(2L);
      nodeD.setData("Company D");
      
      root.addChild(2L,nodeA);
      nodeA.addChild(3L,nodeB);
      nodeA.addChild(4L,nodeC);
      nodeC.addChild(3L,nodeD);
      
      return root;
      }
      
      private UIComponent getTree(){
      return this.tree;
      }
      public void setTree(UIComponent tree){
      this.tree=(UITree)tree;
      }
      
      public String expandAll(){
      try{
      this.tree.queueExpandAll();
      }
      catch(IOException exp){
      exp.printStackTrace();
      }
      
      return null;
      }
      
      public String expandPath(){
      
      String pathtoExpand=getPath();
      if(pathToExpand!=null && pathToExpand.trim().length()!=0){
      try{
      
      this.tree.queueNodeExpand(new ListRowKey(pathToExpand));//getting exception here
      
      //Also tried this
      // TreeState state=(TreeState) this.tree.getComponentState();
      //state.expandNode(this.tree,new ListRowKey(pathToExpand)); Getting excetion here
      }
      catch(IOException exp){
      throw new FacesException(exp);
      }
      return null;
      }
      
      
      }
      
      ---------TreeImpl ----
      
      Tree Impl is simple VO with
      private Long compId;
      private String compNme;
      --setters and getters....
      
      I used same web.xml of demo examples at
      http://livedemo.exadel.com/richfaces-demo/richfaces/tree.jsf
      
      
      


      Thanks.....
      chenna

        • 1. Re: No tree element available or  row key not set.. while ex

          Additional Info:
          Library files I used:
          richfaces-api=3.2.1.GA.jar
          richfaces-impl=3.2.1.GA.jar
          richfaces-ui=3.2.1.GA.jar
          jsf-facelets=1.1.14.jar
          jsf-api-1.2_07.jar

          • 2. Re: No tree element available or  row key not set.. while ex

            Additional Info:
            Library files I used:
            richfaces-api=3.2.1.GA.jar
            richfaces-impl=3.2.1.GA.jar
            richfaces-ui=3.2.1.GA.jar
            jsf-facelets=1.1.14.jar
            jsf-api-1.2_07.jar

            • 3. Re: No tree element available ot  row key not set.. while ex

              Typo errors in managed bean, setted with correct Ids

              
              
              package org.richfaces;
              import java.io.IOException;
              import javax.faces.FacesException;
              import javax.faces.component.UIComponent;
              import javax.faces.event.FacesEvent;
              import org.richfaces.component.UITree;
              import org.richfaces.component.UITreeNode;
              import org.richfaces.event.NodSelectedEvent;
              import org.richfaces.model.ListRowKey;
              
              public class MyTreeBean{
              UITree tree;
              private String path;
              //---setter and getters.. for path
              //......
              public TreeImpl getMyTreeData(){
              TreeImpl root=new TreeImpl();
              root.setData("Root Node");
              
              TreeImpl nodeA=new TreeImpl();
              nodeA.setCompId(2L);
              nodeA.setData("Company A");
              
              TreeImpl nodeB=new TreeImpl();
              nodeB.setCompId(3L);
              nodeB.setData("Company B");
              
              TreeImpl nodeC=new TreeImpl();
              nodeC.setCompId(4L);
              nodeC.setData("Company C");
              
              
              TreeImpl nodeD=new TreeImpl();
              nodeD.setCompId(5L);
              nodeD.setData("Company D");
              
              root.addChild(2L,nodeA);
              nodeA.addChild(3L,nodeB);
              nodeA.addChild(4L,nodeC);
              nodeC.addChild(5L,nodeD);
              
              return root;
              }
              
              private UIComponent getTree(){
              return this.tree;
              }
              public void setTree(UIComponent tree){
              this.tree=(UITree)tree;
              }
              
              public String expandAll(){
              try{
              this.tree.queueExpandAll();
              }
              catch(IOException exp){
              exp.printStackTrace();
              }
              
              return null;
              }
              
              public String expandPath(){
              
              String pathtoExpand=getPath();
              if(pathToExpand!=null && pathToExpand.trim().length()!=0){
              try{
              
              this.tree.queueNodeExpand(new ListRowKey(pathToExpand));//getting exception here
              
              //Also tried this
              // TreeState state=(TreeState) this.tree.getComponentState();
              //state.expandNode(this.tree,new ListRowKey(pathToExpand)); Getting excetion here
              }
              catch(IOException exp){
              throw new FacesException(exp);
              }
              return null;
              }
              
              
              }
              
              ---------TreeImpl ----
              
              Tree Impl is simple VO with
              private Long compId;
              private String compNme;
              --setters and getters....
              
              I used same web.xml of demo examples at
              http://livedemo.exadel.com/richfaces-demo/richfaces/tree.jsf
              
              
              


              • 4. Re: No tree element available ot  row key not set.. while ex
                nbelaevski

                Hello,

                You should use this constructor: org.richfaces.model.ListRowKey.ListRowKey(List) and not this one: org.richfaces.model.ListRowKey.ListRowKey(T).

                • 5. Re: No tree element available ot  row key not set.. while ex

                  Thanks nbelaevski for ur reply...

                  I did as you mentioned..
                  But Still getting the same error " No tree element available or row key not set".
                  I tried following inputs:
                  2
                  2:3
                  2:4
                  2:4:5
                  Please find the updated expandPath()..

                  public String expandPath(){
                  
                  String pathtoExpand=getPath();
                  
                  List lst=new ArrayList();
                  lst.add(pathtoExpand);
                  
                  if(lst!=null & lst.size()>0){
                  try{
                  
                  this.tree.queueNodeExpand(new ListRowKey(lst));// getting exception here
                  
                  //Also tried this
                  // TreeState state=(TreeState) this.tree.getComponentState();
                  //state.expandNode(this.tree,new ListRowKey(lst)); Getting excetion here
                  }
                  catch(IOException exp){
                  throw new FacesException(exp);
                  }
                  return null;
                  }
                  }
                  
                  


                  Thanks.....

                  • 6. Re: No tree element available ot  row key not set.. while ex
                    nbelaevski

                    You are using Long as key and String in the list. You should provide List of Long for this to work.

                    • 7. Re: No tree element available ot  row key not set.. while ex

                      Thank you very much nbelaevski...
                      Now i am not getting any exception,
                      consider this is my whole tree
                      --------A--------- (id=2)
                      -----B----C------(B ..id=3 C.. id=4 )
                      ------------D---------(id=5)
                      ----------E----F--------(E ..id=6 F.. id=7 )

                      Here A is root , B and C are its first level children
                      C is has child D and D is having children E and F...

                      List lst=new ArrayList();
                      lst.add(2L);
                      ....
                      this.tree.queueNodeExpand(new RowList(lst));

                      It is working fine, it is expanding A(i.e; showing B and C nodes ).

                      I want to expand node D..
                      I changed as follows..

                      lst.add(2L);
                      lst.add(4L);
                      lst.add(5L);
                      ....
                      this.tree.queueNodeExpand(new RowList(lst));

                      I am not getting any exception, but Node D is not expanding...


                      Above code is working only when Node C already expanded..


                      If I give any RowKey, why richfaces not taking care of expanding it's parent nodes.
                      Am I missing anything?
                      Please advise
                      Thanks...





                      • 8. Re: No tree element available ot  row key not set.. while ex
                        nbelaevski

                        But node D is expanded even if node C is not. You can expand C node in the usual way (using "plus" controls) after programmatic expansion of D and see that D has the desired expanded state.

                        • 9. Re: No tree element available ot  row key not set.. while ex
                          derkd

                           

                          "nbelaevski" wrote:
                          But node D is expanded even if node C is not. You can expand C node in the usual way (using "plus" controls) after programmatic expansion of D and see that D has the desired expanded state.


                          I also have the same problem. What do you mean with "plus controls"? can you give a short example of how the expand the parent nodes?

                          • 10. Re: No tree element available ot  row key not set.. while ex
                            derkd

                             

                            "derkd" wrote:
                            "nbelaevski" wrote:
                            But node D is expanded even if node C is not. You can expand C node in the usual way (using "plus" controls) after programmatic expansion of D and see that D has the desired expanded state.


                            I also have the same problem. What do you mean with "plus controls"? can you give a short example of how the expand the parent nodes?


                            I got it, although there should be a more nicer way...

                            Iterator<?> iter = rowKeyToExpand.iterator();
                             ArrayList<Long> list = new ArrayList<Long>();
                             while (iter.hasNext()) {
                             Long id = (Long)iter.next();
                             log.debug("id: " + id);
                             list.add(id);
                             htmlTree.queueNodeExpand(new ListRowKey(list));
                             }

                            is this the right way? or is there a better sollution?