Rich:Tree Basics Question
andygibson Jan 2, 2008 12:33 PMI'm using Seam and trying to build my own TreeNode implementations without success. I've created a simple test TreeNode to try and get it working which I've included below :
public class TestTreeNode implements Serializable, TreeNode { private Object data = null; private Map<Object, TreeNode> childNodes = null; private int level; public TestTreeNode(Object data) { this.data = data; this.level = 0; } protected Map<Object, TreeNode> getChildList() { //generate some random ndoes up to level 3 tree levels if (childNodes == null) { childNodes = new HashMap<Object, TreeNode>(); if (level < 3) { for (int i = 1; i < 3; i++) { String s = String.valueOf(i); TestTreeNode node = new TestTreeNode(s); node.level = level + 1; childNodes.put(s, node); } } } return childNodes; } public void addChild(Object identifier, TreeNode child) { getChildList().put(identifier, child); } public TreeNode getChild(Object id) { return getChildList().get(id); } public Iterator getChildren() { return getChildList().entrySet().iterator(); } public Object getData() { return data; } public TreeNode getParent() { return null; } public boolean isLeaf() { return false; } public void removeChild(Object id) { getChildList().remove(id); } public void setData(Object data) { this.data = data; } public void setParent(TreeNode parent) { // TODO Auto-generated method stub } @Override public String toString() { return "TestTreeNode : " + data; } }
It simply creates a set of tree nodes with 2 child nodes each upto a depth of 3 levels.
My web page is defined as :
<rich:tree switchType="server" ajaxSubmitSelection="true" value="#{userRightAssignment.treeData}" var="v_node"> <rich:treeNode type="simpleNode"> <h:outputText value="#{v_node}" /> </rich:treeNode> </rich:tree>
In my backing bean (which is bean created fine) I have
private TreeNode node = new TestTreeNode("1"); ... ... ... public TreeNode getTreeData() { return node; }
The tree is being created ok, I've created a method to write out the tree recursively to the log, and it comes out fine. However, in the page itself, there is nothing in the tree, no icons, no text etc..
I couldn't find a simplistic example of implementing the tree node interface so I'm guessing, but I think I'm missing something out here.
Anyone got any insights?
Cheers,
Andy