1 Reply Latest reply on Sep 14, 2010 8:46 AM by harut

    Rich tree problem

    krikorherlopian

      I have  table from database. I read it correct.It has a code  and name. I display three tree by names. But when its selected I want to know the code not the name.

      How can I make it?

       

      <rich:tree  style="width:300px" nodeSelectListener="#{menu.processSelection}"
                      ajaxSubmitSelection="true"  switchType="ajax"
                      value="#{menu.treeNode}" var="item">
                      <a4j:support event="onselected"   reRender="bPan" ></a4j:support>

       


                   
                  </rich:tree>

       

      public void processSelection(NodeSelectedEvent event) {
              HtmlTree tree = (HtmlTree) event.getComponent();
              nodeTitle = (String) tree.getRowData();
              selectedNodeChildren.clear();
              System.out.println("deeeeerrr");
              TreeNode currentNode = tree.getModelTreeNode(tree.getRowKey());
              if (currentNode.isLeaf()){
                 
                  selectedNodeChildren.add((String)currentNode.getData());
                  System.out.println("entered here "+currentNode.getData());
                  selected = (String)currentNode.getData();
              }else
              {
                  Iterator<Map.Entry<Object, TreeNode>> it = currentNode.getChildren();
                  while (it!=null &&it.hasNext()) {
                      Map.Entry<Object,TreeNode > entry = it.next();
                      selectedNodeChildren.add(entry.getValue().getData().toString());
                      System.out.println("entered here2 "+entry.getValue().getData().toString());
                  }
                  selected = (String)currentNode.getData();
              }
          }

       

      proccess selection will read the name, because i show the names. not the code. can i make the code hidden somwhere? and read it in process selection somehow?

      anyone got solution?         

        • 1. Re: Rich tree problem
          harut

          you can use any bean object as tree node for the rich tree, and construct the tree based on that bean objects... you can store any data you want in the bean object corresponding property (in your case 'code')... Then in 'processSelection' method you can get the object which corresponds to selected node, and after it get the needed property... Also there is no need to add a4j:support in the rich:tree for selection handling purposes. There is already an attribute in the rich:tree for that "nodeSelectListener="#{yourBean.processSelection}""...

          Get the selected tree node in the processSelection method:


          (MyBean) selectedNode = (MyBean) ((UITree) nodeSelectedEvent.getComponent()).getRowData();

          String code = selectedNode.getCode();

          ......