how can I build a simple recursive heirarchical rich:tree?
nimzo Jun 8, 2011 11:32 AMHi,
I need build a rich:tree with a recursive heirarchical but I don't know if it can work fine with List, arrayList, collections, etc... I don't know how built my classes for it. I saw the example simple treeModelRecursiveAdaptor usage from http://richfaces-showcase.appspot.com/richfaces/component-sample.jsf?demo=treeAdaptors&sample=treeModelRecursiveAdaptor&skin=blueSky but it is very complicate for me. I need other example more easy.
I don't understand the FileSystemNode.java and the line: Iterables.addAll(directories, transform(filter(getResourcePaths(), containsPattern("/$")), FACTORY));
I need a simple tree where the information of each node is: id, name and list of childs.(All nodes of the same type).
Also I 've the follow code but it don' display nothing:
<rich:tree toggleType="ajax" var="item">
<rich:treeModelRecursiveAdaptor roots="menuArbolBean.menus" nodes="#{item.children}">
<rich:treeNode>#{item.nombre}</rich:treeNode>
</rich:treeModelRecursiveAdaptor>
</rich:tree>
I don't understand the line: <rich:treeModelRecursiveAdaptor roots="menuArbolBean.menus" nodes="#{item.children}">
because I don't know if I can use a simple list in the attribute roots and nodes.
My classes are:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package Seguridad.Beans;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
@ManagedBean
@RequestScoped
public class MenuArbolBean {
private List<MenuNode> menusArbol;
public synchronized List<MenuNode> getMenus() {
//public synchronized MenuNode[] getMenus() {
if (menusArbol == null) {
//srcRoots = new FileSystemNode().getDirectories();
MenuNode nodo = new MenuNode();
menusArbol = nodo.getChildren();
}
/*for (int i=0;i<menus.size();i++)
{
MenuNode nodo = (MenuNode)menus.get(i);
System.out.println("NODO:" + nodo.getNombre());
}*/
return menusArbol;
}
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package Seguridad.Beans;
import com.google.common.collect.Lists;
import java.util.ArrayList;
import java.util.List;
public class MenuNode {
private String nombre;
//private static MenuNode[] CHILDREN_ABSENT = new MenuNode[0];
//private MenuNode[] children;
private static List<MenuNode> CHILDREN_ABSENT = new ArrayList<MenuNode>();
private List<MenuNode> children;
public MenuNode() {
}
public void setNombre(String nombre)
{
this.nombre = nombre;
}
public String getNombre()
{
return (this.nombre);
}
public synchronized void setChildren(List<MenuNode> children) {
this.children = children;
}
public synchronized List<MenuNode> getChildren() {
//public synchronized MenuNode[] getChildren() {
/*directories = Lists.newArrayList();
childre*/
//MenuNode[] padre;
if (children == null) {
List<MenuNode> children = Lists.newArrayList();
try
{
MenuNode nodo = new MenuNode();
List<MenuNode> hijos = Lists.newArrayList();
nodo = new MenuNode();
nodo.setNombre("Gestión Aplicaciones");
nodo.setChildren(CHILDREN_ABSENT);
hijos.add(nodo);
nodo = new MenuNode();
nodo.setNombre("Gestión Perfiles");
nodo.setChildren(CHILDREN_ABSENT);
hijos.add(nodo);
nodo = new MenuNode();
nodo.setNombre("Aplicaciones");
nodo.setChildren(hijos);
children.add(nodo);
//padre = new MenuNode[1];
//padre[0] = nodo;
//MenuNode[] hijos = new MenuNode[2];
}
catch(Exception e)
{
children = null;
}
}
return children;
}
}
Thank you