dynamical rich tree
franckoliver Jan 18, 2011 11:31 AMDoes anybody know how to build a tree dynamically? I tried it with the changeExpandListener on the rich tree component but it doesn t seem to work. I'm trying to get on the bean the id of the component that should be expanded, retreive the childrens of the component and update the tree.
here is the code snippet:
<h:form>
<rich:tree styleClass="mytree" style="width:300px" value="#{transport.data}" var="item" nodeFace="#{item.type}" switchType="ajax" ajaxSubmitSelection="true">
<rich:treeNode type="container" icon="/img/container-yellow.png" changeExpandListener="#{transport.containerExpand()}">
<h:commandLink value="#{item.name}"/>
<f:param name="containerID" value="#{item.id}"/>
</rich:treeNode>
<rich:treeNode type="pallet" icon="/img/icon_pallet.jpg" changeExpandListener="#{transport.palletExpand()}">
<h:commandLink value="#{item.name}" />
<f:param name="palletID" value="#{item.id}"/>
</rich:treeNode>
<rich:treeNode id="nodId" type="product" icon="/img/icon_paket.gif">
<h:commandLink value="#{item.name}" />
</rich:treeNode>
<h:outputText value="#{item.id}"/>
</rich:tree>
</h:form>
...............................................................................................................................................................................
public void containerExpand() {
//FacesContext fc = FacesContext.getCurrentInstance();
//Map<String,String> params = fc.getExternalContext().getRequestParameterMap();
Container container = new Container(containerID);
addChildrenNodes(container);
}
public void addChildrenNodes(TreeNode node){
//process your node somehow. For this example I add only one node.
TreeNodeImpl newNode = new TreeNodeImpl();
newNode.setData("Pallet 0");
newNode.setParent(node);
node.addChild("rowKey", newNode);
}