3 Replies Latest reply on Jul 22, 2010 5:59 AM by Ilya Shaikovsky

    rich:tree implementation problem

    Hakan Moral Newbie

      hello i am trying to create a hierarchical tree of


      document types

                     -> document types2

                           -> document years


      and the types, types2 and years of the documents are taken from the tables in a db.


      i followed the samples given in the richfaces 3.3.3 final but i can see only the root element in the tree and tree does not respond to clicking for expanding. I debugged and can see the Treenodeimpl structure correctly but i could not be able to show it up in the view. the code is below:



      public class DocTreeManagerBean implements DocTreeManager, Serializable
          private static final long serialVersionUID = 3390747870940320057L;
          private static final String PDOCTYPELISTSQL = "SELECT doctypes from Pdoctype doctypes";
          private static final String DOCUMENTLISTSQL = "SELECT docsoffirm from VDocsOfFirm docsoffirm WHERE docsoffirm.firmtaxnum= :firmtaxnum ORDER BY firmtaxnum, docid, ddate";


          public enum doctypes {FIRM, PDOCTYPE, DOCYEAR, FAIR, FAIRNAME, DOCUMENT};
          @Logger private Log log;


          @In StatusMessages statusMessages;


          @In EntityManager entityManager;
          @In (value="firmFound", scope=ScopeType.CONVERSATION, required=false)
          private Firm firm;
          private String value;


          private TreeNodeImpl<DocTreeNode> treeRootNode = null;
          private TreeNodeImpl<DocTreeNode> treeNodeImpl=null;
          private Long firmTaxNo;


          private List<Document> listOfDocs;
          private List<Pdoctype> docTypes;
          private List<VDocsOfFirm> docsOfFirm;
          //kullanici secim olaylari:
          private DocTreeNode nodeTitle;
          private List<DocTreeNode> selectedNodeChildren = new ArrayList<DocTreeNode>();   


          public void selectionListener(NodeSelectedEvent event){
              UITree tree = (UITree) event.getComponent();
              nodeTitle = (DocTreeNode) tree.getData();
          public void expansionListener(NodeExpandedEvent event){
              UITree tree =(UITree) event.getComponent();
              nodeTitle=(DocTreeNode) tree.getData();
          public void docTreeManager()
              // implement your business logic here
              log.info("docTreeManager.docTreeManager() action called with: #{docTreeManager.value}");
              statusMessages.add("docTreeManager #{docTreeManager.value}");


          ///root: documan turleri ekleniyor:
          public void addDocNodes(){
              treeRootNode = new TreeNodeImpl<DocTreeNode>();
              treeNodeImpl = new TreeNodeImpl<DocTreeNode>();
              DocTreeNode anyNode = null;
              //TODO duzeltilecek cok daha duzgun hale getirilmesi gerekiyor, tekrarli kod var.
              if(null != firm) {
                  firmTaxNo = firm.getFtaxnum();
                  anyNode = new DocTreeNode();
                  //dokuman turleri:
                  Query query = entityManager.createQuery(PDOCTYPELISTSQL);
                  //firmanin sistemdeki dokumanlari
                  query = entityManager.createQuery(DOCUMENTLISTSQL).setParameter("firmtaxnum", firmTaxNo);
                  //firma vergi nosu root
                  //treeRootNode = treeNodeImpl;
                  //treeRootNode.addChild(0, treeNodeImpl);
                  //dokuman turlerini gir:
                  int count=0;
                  for(Pdoctype doctype : docTypes){
                      String nodeStr = doctype.getPdoctype();
                      TreeNodeImpl<DocTreeNode> nodeDoctype = new TreeNodeImpl<DocTreeNode>();
                      anyNode = new DocTreeNode();
                      treeNodeImpl.addChild(count++, nodeDoctype);
                  treeRootNode.addChild(0, treeNodeImpl);
              } else {
                  treeRootNode.addChild(1, treeNodeImpl);


          //firmanin dokumanlarindan nodeStr olanlarini tarihe gore ekleyecek.
          private void addDateNodes(TreeNode<DocTreeNode> node, String nodeStr){
              TreeNode<DocTreeNode> dateNodes = new TreeNodeImpl<DocTreeNode>();
              int dateCounter=1;
              DocTreeNode anyNode = null;
              for(VDocsOfFirm doc : docsOfFirm){
                      TreeNodeImpl<DocTreeNode> treenode =  new TreeNodeImpl<DocTreeNode>();
                      anyNode = new DocTreeNode();
                      dateNodes.addChild(dateCounter++, treenode);
                      if(doc.getFuaradi()!=null && doc.getFuaradi().length()>0) {
                          addFuarNode(treenode, nodeStr, doc);
              node.addChild(nodeStr, dateNodes);
          //firmanin eklenen dokumanlarindan verilen tarihe ait olan eger
          //destek ise (fuaradi bos degilse) ekleyecek: gelen node a fuaradini ekleyecek.
          private void addFuarNode(TreeNode<DocTreeNode> node, String nodeStr, VDocsOfFirm doc){
              TreeNodeImpl<DocTreeNode> treeNode = new TreeNodeImpl<DocTreeNode>();
              DocTreeNode anyNode = new DocTreeNode();
              node.addChild(0, treeNode);


          public void processSelection(NodeSelectedEvent event) {
              HtmlTree tree = (HtmlTree) event.getComponent();
              nodeTitle = (DocTreeNode) tree.getRowData();
              TreeNode currentNode = tree.getModelTreeNode(tree.getRowKey());
              if (currentNode.isLeaf()){
                  Iterator<Map.Entry<Object, TreeNode>> it = currentNode.getChildren();
                  while (it!=null &&it.hasNext()) {
                      Map.Entry<Object, TreeNode> entry = it.next();

          @Length(max = 10)
          public String getValue()
              return value;


          public void setValue(String value)
              this.value = value;


          @Remove @Destroy
          public void destroy() {}


          public void setTreeRootNode(TreeNodeImpl<DocTreeNode> treeRootNode) {
              this.treeRootNode = treeRootNode;


          public TreeNode getTreeRootNode() {
              if(null == treeRootNode)
              return treeRootNode;


          public void setFirmTaxNo(Long firmTaxNo) {
              this.firmTaxNo = firmTaxNo;


          public Long getFirmTaxNo() {
              return firmTaxNo;


          public void setListOfDocs(List<Document> listOfDocs) {
              this.listOfDocs = listOfDocs;


          public List<Document> getListOfDocs() {
              return listOfDocs;


          public void setDocTypes(List<Pdoctype> docTypes) {
              this.docTypes = docTypes;


          public List<Pdoctype> getDocTypes() {
              return docTypes;


          public void setDocsOfFirm(List<VDocsOfFirm> docsOfFirm) {
              this.docsOfFirm = docsOfFirm;


          public List<VDocsOfFirm> getDocsOfFirm() {
              return docsOfFirm;


          public void setNodeTitle(DocTreeNode nodeTitle) {
              this.nodeTitle = nodeTitle;


          public DocTreeNode getNodeTitle() {
              return nodeTitle;


      DocTreeNode - holds the data shown in the tree:


      public class DocTreeNode implements Serializable{

          private static final long serialVersionUID = -2014941341643021587L;

          private String title;

          private doctypes doctype;
          private String type;
          private Object obj;
          public void setTitle(String title) {
              this.title = title;
          public String getTitle() {
              return title;
          public void setDoctype(doctypes value) {
              this.doctype = value;
          public doctypes getDoctype() {
              return doctype;
          public void setObj(Object obj) {
              this.obj = obj;
          public Object getObj() {
              return obj;

          public void setType(String type) {
              this.type = type;
          public String getType() {
              return type;
          public String toString(){
              return title;



      view to show in the browser:


                  <rich:tree style="width:300px" nodeSelectListener="#{docTreeManager.processSelection}"
                      ajaxSubmitSelection="true"  switchType="ajax"
                      value="#{docTreeManager.treeRootNode}" var="item" ajaxKeys="#{null}">


      any suggestions will be appreciated.