5 Replies Latest reply on May 21, 2007 12:22 PM by c_eric_ray

    Rich:tree (not displayed)

    mrnice

      Hey, after trying a long day to get the Rich:tree component to work I have to ask you to get some input of what i might doing wrong.

      I tried to use the example Code and build my own application on it.

      Here is my JSP:

      rich:tree style="width:300px" value="#{treeBean.data}" var="item" nodeFace="#{item.type}">
       <rich:treeNode type="root">
       <h:outputText value="#{item.type}" />
       </rich:treeNode>
       </rich:tree>


      Here is my backing Bean

      package bocis.adowx.backingBeans;
      
      
      import java.io.Serializable;
      import java.util.HashMap;
      import java.util.Iterator;
      import java.util.Map;
      
      import org.richfaces.component.TreeNode;
      
      import bocis.adowx.basic.ADOwxBaseBean;
      import bocis.adowx.tree.ADOwxTreeGroup;
      import bocis.adowx.tree.ADOwxTreeModel;
      import bocis.adowx.tree.IADOwxTreeNode;
      
      
      public class ADOwxTreeBean extends ADOwxBaseBean implements TreeNode, Serializable {
      
       private static final long serialVersionUID = -1410719824643866404L;
      
       private Map<Object, TreeNode> models = null;
      
       private Object state1;
      
       private Object state2;
      
       public ADOwxTreeBean()
       {
       initData();
       }
      
       private Map<Object, TreeNode> getModels() {
       if (this.models == null) {
       initData();
       }
       return this.models;
       }
      
       public void addNode(IADOwxTreeNode node) {
       addChild(Long.toString(node.getId()),(TreeNode) node);
       ((TreeNode)node).setParent(this);
       }
      
       public void addChild(Object identifier, TreeNode child) {
       getModels().put(identifier, child);
       }
      
       public TreeNode getChild(Object id) {
       return (TreeNode) getModels().get(id);
       }
      
       public Iterator getChildren() {
       return getModels().entrySet().iterator();
       }
      
       public Object getData() {
       return this;
       }
      
       public TreeNode getParent() {
       return null;
       }
      
       public boolean isLeaf() {
       return getModels().isEmpty();
       }
      
       public void removeChild(Object id) {
       getModels().remove(id);
       }
      
       public void setData(Object data) {
       }
      
       public void setParent(TreeNode parent) {
       }
      
       public String getType() {
       return "root";
       }
      
       private long nextId = 0;
      
       private long getNextId() {
       return nextId++;
       }
      
       private void initData() {
      
       models = new HashMap();
      
       ADOwxTreeGroup group1 = new ADOwxTreeGroup(0);
       group1.setName("Fritz");
       addChild(Long.toString(group1.getId()), group1);
       }
      
       public Object getState1() {
       return state1;
       }
      
       public void setState1(Object state1) {
       this.state1 = state1;
       }
      
       public Object getState2() {
       return state2;
       }
      
       public void setState2(Object state2) {
       this.state2 = state2;
       }
      }


      and here is another TreeNode (the intention of this is to represent a folder)

      package bocis.adowx.tree;
      
      import java.util.HashMap;
      import java.util.Iterator;
      import java.util.Map;
      
      import org.richfaces.component.TreeNode;
      
      import bocis.adowx.basic.IADOwxID;
      
      
      public class ADOwxTreeGroup implements TreeNode,IADOwxTreeNode{
      
       /*private static final long serialVersionUID = 6514596192023597908L;
       private long id;
       private Map songs = new HashMap();
       private String title;
       private Integer year;
       private Artist artist;*/
      
       private static final long serialVersionUID = 5406170156133072186L;
      
       private long id;
       private Map models = new HashMap();
       private TreeNode parent;
       private String name;
      
       public ADOwxTreeGroup(long id)
       {
       this.id = id;
       }
      
       public void addModel(ADOwxTreeModel model)
       {
       addChild(Long.toString(model.getId()), model);
       model.setParent(this);
      
       }
      
       public void addChild(Object identifier, TreeNode child) {
       models.put(identifier, child);
       }
      
       public TreeNode getChild(Object arg0) {
       return (TreeNode) models.get(id);
       }
      
       public Iterator getChildren() {
       return models.entrySet().iterator();
       }
      
       public Object getData() {
       return this;
       }
      
       public TreeNode getParent() {
       // TODO Verweis auf Parent Objekt einbinden
       return parent;
       }
      
       public boolean isLeaf() {
       return models.isEmpty();
       }
      
       public void removeChild(Object id) {
       models.remove(id);
       }
      
       public void setData(Object arg0) {
       }
      
       public void setParent(TreeNode parent) {
       this.parent = parent;
       }
      
      
       public long getId()
       {
       return id;
       }
      
       public String getType() {
       return "group";
       }
      
       public void setId(long id) {
       this.id = id;
       }
       public String getName()
       {
       return this.name;
       }
       public void setName(String name)
       {
       this.name = name;
       }
      
      }



      I don't get a error in JSF, but if i use Firebug with Firefox i get this error:

      this.elements.contentTd has no properties


        • 1. Re: Rich:tree (not displayed)
          mrnice

          Sorry, this is the JSP: (added Treenode fpr type="group")

          <rich:tree style="width:300px" value="#{treeBean.data}" var="item" nodeFace="#{item.type}">
           <rich:treeNode type="root">
           <h:outputText value="#{item.type}" />
           </rich:treeNode>
           <rich:treeNode type="group">
           <h:outputText value="#{item.type}" />
           </rich:treeNode>
           </rich:tree>
          


          Many many thanks in advance, I am totally stuck right now.

          Is there a complete tutorial or example on how to create the tree?


          • 2. Re: Rich:tree (not displayed)
            mrnice

            Btw: I get the firebug error message

            this.elements.contentTd has no properties


            even if i only add a empty Tree into my JSF Page.



            • 3. Re: Rich:tree (not displayed)
              mrnice

              plz delete this post, as i solved it by again reeimplementing the examples.

              Thx

              • 4. Re: Rich:tree (not displayed)
                cormet

                Hi mrnice,

                Can you shared about the problem that u encounter during tree development?
                coz i have the same problem as you describe here.

                can you point shared your example code with the simple class...

                cheers,

                -T

                • 5. Re: Rich:tree (not displayed)

                  it's document that nothing is displayed for the root node. you must have subsequent treeNode which actually displays the first level nodes.