1 Reply Latest reply on Jun 25, 2007 1:33 PM by danielnp

    ***** rich:tree not render *****

    danielnp

      Hi I have the following code but the tree not rendered....
      I use RichFaces 3.0.1 and Ajax4JSF1.1.1 and Sun implementation.


      package mais;
      
      import java.util.HashMap;
      import java.util.Iterator;
      import java.util.Map;
      
      import org.richfaces.component.TreeNode;
      
      public class GrupoEmpresaTreeControl implements TreeNode{
      
       /**
       *
       */
       private static final long serialVersionUID = 2061068512715155849L;
       private Map grupos = null;
       private String descricao = "pai";
       private Long id = new Long(0);
      
      
       public GrupoEmpresaTreeControl() {
       initData();
       }
      
       private Map getGrupos() {
       if (this.grupos==null) {
       initData();
       }
       return this.grupos;
       }
      
       public void addGrupoEmpresaTree(GrupoEmpresaTree grupoEmpresaTree) {
       addChild(grupoEmpresaTree.getId(), grupoEmpresaTree);
       grupoEmpresaTree.setParent(this);
       }
      
       @SuppressWarnings("unchecked")
       public void addChild(Object identifier, TreeNode child) {
       getGrupos().put(identifier, child);
       }
      
       public TreeNode getChild(Object id) {
       return (TreeNode) getGrupos().get(id);
       }
      
       public Iterator getChildren() {
       return getGrupos().entrySet().iterator();
       }
      
       public Object getData() {
       return this;
       }
      
       public TreeNode getParent() {
       return null;
       }
      
       public boolean isLeaf() {
       return getGrupos().isEmpty();
       }
      
       public void removeChild(Object id) {
       getGrupos().remove(id);
       }
      
       public void setData(Object data) {}
      
       public void setParent(TreeNode parent) {}
      
       public String getType() {
       return "grupoempresacontrol";
       }
      
      
      
       public String getDescricao() {return descricao;}
       public void setDescricao(String descricao) {this.descricao = descricao;}
      
       public Long getId() {return id;}
       public void setId(Long id) {this.id = id;}
      
      
      
       @SuppressWarnings("unchecked")
       private void initData() {
       if (grupos == null){
       grupos = new HashMap();
       //GrupoEmpresaTree p;
       GrupoEmpresaTree f;
      
       f = new GrupoEmpresaTree(new Long(1));
       f.setDescricao("Nivel 1");
       addGrupoEmpresaTree(f);
      
       f = new GrupoEmpresaTree(new Long(2));
       f.setDescricao("Nivel 2");
       addGrupoEmpresaTree(f);
      
       f = new GrupoEmpresaTree(new Long(3));
       f.setDescricao("Nivel 3");
       addGrupoEmpresaTree(f);
       /*
       p=f;
       f = new GrupoEmpresaTree();
       f.setDescricao("Filho Nivel 1");
       p.addChild(new Long(2), f);
       //grupos.put(p, f);
      
       f = new GrupoEmpresaTree();
       f.setDescricao("Nivel 2");
       grupos.put(new Long(3), f);
       */
       }
       }
      
      }
      



      package mais;
      
      import java.util.ArrayList;
      import java.util.Iterator;
      
      import org.richfaces.component.TreeNode;
      
      public class GrupoEmpresaTree implements TreeNode{
       private Long id;
       private String descricao;
       private GrupoEmpresaTreeControl grupoEmpresaTreeControl;
       private static final long serialVersionUID = -1471377200156566830L;
      
      
       public GrupoEmpresaTree(Long id) {
       this.id = id;
       }
      
      
       @SuppressWarnings("unchecked")
       public void addChild(Object identifier, TreeNode child) {
       throw new UnsupportedOperationException("Não suporta mais filho.");
       }
      
       public TreeNode getChild(Object grupo) {
       throw new UnsupportedOperationException("Não suporta mais filho.");
       }
      
       public Iterator getChildren() {
       return new ArrayList().iterator();
       }
      
       public Object getData() {
       return this;
       }
      
       public TreeNode getParent() {
       return grupoEmpresaTreeControl;
       }
      
       public boolean isLeaf() {
       return true;
       }
      
       public void removeChild(Object grupo) {
       throw new UnsupportedOperationException("Não existtem filhos para remoção!");
       }
      
       public void setData(Object data) {}
      
       public void setParent(TreeNode parent) {
       grupoEmpresaTreeControl = (GrupoEmpresaTreeControl) parent;
       }
      
       public String getType() {
       return "grupoempresa";
       }
      
      /*
       * GETTERS AND SETTERS
       */
       public String getDescricao() {return descricao;}
       public void setDescricao(String descricao) {this.descricao = descricao;}
      
       public Long getId() {return id;}
       public void setId(Long id) {this.id = id;}
      }
      
      


      <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
      <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
      <%@ taglib uri="http://richfaces.ajax4jsf.org/rich" prefix="rich"%>
      
      <html>
      
      <f:view>
      
       <head>
       <title>Bem Vindo ao MAIS !!!</title>
       </head>
       <body>
       <h:form id="formIndex">
      
      
       <table border="1" width="100%" height="100%" cellpadding="0" cellspacing="0">
       <tr height="100%">
       <td valign="top" align="center">
      
       <rich:panel>
       <f:facet name="header">
       <h:outputText value="Cabecalho" />
       </f:facet>
       <h:outputText value="Corpo" />
       </rich:panel>
      
      
       <div class="sample-container">
      
       <rich:tree styleClass="nav-tree" switchType="server" id="idTree" style="width:100%" value="#{tree.data}" var="item" nodeFace="#{item.type}">
      
       <rich:treeNode type="grupoempresacontrol">
       <h:outputText value="teste" />
       </rich:treeNode>
      
       <rich:treeNode type="grupoempresa">
       <h:outputText value="#{item.descricao}" />
       </rich:treeNode>
      
       </rich:tree>
      
       </div>
       </td>
       </tr>
       </table>
      
       </h:form>
       </body>
      </f:view>
      </html>
      


      Help me!