6 Replies Latest reply on Jan 7, 2008 3:11 AM by Nicklas Karlsson

    Richfaces Tree

    Richard Mokua Newbie

      Hi everyone
      I have tried using rich-faces tree, but quite frankly
      am not able to display a tree.
      Note that other rich-faces components are being displayed correctly.
      I followed this
      and this http://www.jboss.com/index.html?op=loginscreen&module=user
      but still got no-where!

      Is there anyone using rich-faces tree?I will greatly appreciate any help.

      seam 1.2.1 GA
      jboss-4.0.5 GA

      Here is the Node :

      package com.triad.treeNodes;
      import java.util.Iterator;
      import java.util.LinkedHashMap;
      import java.util.Map;
      import org.jboss.seam.ScopeType;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.Scope;
      import org.richfaces.component.TreeNode;
      public class RichTreeNode implements TreeNode {
       private static final long serialVersionUID = 1L;
       // private TreeNode treeNode;
       private String name;
       private String type;
       private Map<Object, TreeNode> childrenMap = new LinkedHashMap<Object, TreeNode>();
       public Object getData() {
       // return treeNode;
       return this;
       public void setData(Object arg0) {
       public boolean isLeaf() {
       return childrenMap.size() == 0;
       public Iterator getChildren() {
       return childrenMap.entrySet().iterator();
       public TreeNode getChild(Object identifier) {
       return childrenMap.get(identifier);
       public void addChild(Object identifier, TreeNode treeNode) {
       childrenMap.put(identifier, treeNode);
       public void removeChild(Object arg0) {
       // TODO Auto-generated method stub
       public TreeNode getParent() {
       return null;
       public RichTreeNode() {
       this.name = "parent-node";
       this.type = "root";
       public void setParent(TreeNode arg0) {
       // TODO Auto-generated method stub
       public String getName() {
       return name;
       public void setName(String name) {
       this.name = name;
       public String getType() {
       return type;
       public void setType(String type) {
       this.type = type;

      Manager bean:
      package com.triad.sessionBeans.tree;
      import java.io.Serializable;
      import java.util.Iterator;
      import javax.faces.component.UIComponent;
      import javax.faces.component.html.HtmlOutputText;
      import javax.faces.component.html.HtmlPanelGrid;
      import javax.faces.component.html.HtmlPanelGroup;
      import javax.faces.context.FacesContext;
      import org.jboss.seam.ScopeType;
      import org.jboss.seam.annotations.Create;
      import org.jboss.seam.annotations.Logger;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.Scope;
      import org.jboss.seam.log.Log;
      import org.richfaces.component.html.HtmlPanel;
      import org.richfaces.component.html.HtmlTree;
      import org.richfaces.component.html.HtmlTreeNode;
      import com.triad.treeNodes.RichTreeNode;
      public class MenuBean implements Serializable{
       private static final long serialVersionUID = 1L;
       private Log log;
       private RichTreeNode richTree;
       public void init(){
       log.info("********* init **********************");
       richTree=new RichTreeNode();
       log.info("has created the tree==>"+richTree);
       RichTreeNode node1=new RichTreeNode();
       node1.setName("Node 1");
       log.info("the tree with children *********");
       Iterator it=richTree.getChildren();
       log.info("***** the node ==>"+it.next());
       public RichTreeNode getRichTree() {
       return richTree;
       public void setRichTree(RichTreeNode richTree) {
       this.richTree = richTree;
       public MenuBean() {

      Now display:
      <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
      <ui:composition xmlns="http://www.w3.org/1999/xhtml"
       <ui:define name="body">
       <h:messages globalOnly="true" styleClass="message" />
       <h:form >
       <h:outputText value="Node - Test"/>
       <a:outputPanel ajaxRendered="true">
       <rich:tree id="directoryTree" switchType="ajax"
       value="#{menu.richTree}" var="d"
       style="margin: 10px;width:300px"
       <h:outputText value="Node - ** #{d.name}"/>

        • 1. Re: Richfaces Tree
          Damian Harvey Master

          The only thing I noticed was that your addChild identifier is a String:

          Whereas the examples and mine use an Integer. I recall having some problems with this as well so try:
          int myIndex = 0;
          richTree.addChild(new Integer(myIndex++),node1);

          It's also probably worth using the TreeNodeImpl rather than rolling your own until you get it going.



          • 2. Re: Richfaces Tree
            Juan Rodriguez Newbie


            Could you display the tree?

            if you could display the tree...could you please show me the code



            • 3. Re: Richfaces Tree
              fanto black Newbie

              I have met the same issue, could any one give me an example?

              • 4. Re: Richfaces Tree
                Nicklas Karlsson Master

                Does this work:

                 <rich:panel header="Tree">
                 <rich:tree value="#{treebean.tree}" var="node">
                 <h:outputText value="#{node}"/>

                public class TreeBean {
                 private TreeNode tree = new TreeNodeImpl();
                 public void createTree() {
                 TreeNodeImpl fooNode = new TreeNodeImpl();
                 TreeNodeImpl barNode = new TreeNodeImpl();
                 TreeNodeImpl tarNode = new TreeNodeImpl();
                 tree.addChild("foo", fooNode);
                 fooNode.addChild("bar", barNode);
                 barNode.addChild("tar", tarNode);
                 public TreeNode getTree() {
                 return tree;
                 public void setTree(TreeNode tree) {
                 this.tree = tree;

                It has a simple string as node data and uses strings for ids

                • 5. Re: Richfaces Tree
                  fanto black Newbie

                  I have got the tree. and one more thing i want to know, does richface tree support vertical dispaly? Not jusft from left to right, what about from top to bottom?

                  • 6. Re: Richfaces Tree
                    Nicklas Karlsson Master

                    I'm having a hard time imagining a "top to bottom" tree. Check the documentation and try asking in the RichFaces forum...