Help!,the property 'var' of tree doesn't play role
bradford Jan 10, 2008 9:59 PMThe following is my tree:
<rich:tree style="width:300px" switchType="client" value="#{simpleTreeBean.treeNode}" var="item" nodeFace="#{item.type}"> <rich:treeNode type="common"> <h:selectBooleanCheckbox value="#{item.selected}"/> <h:outputText value="#{item.title}" /> </rich:treeNode> </rich:tree>
SimpleTreeBean
public class SimpleTreeBean { private CommonNode rootNode = null; //init tree; private CommonNode getTreeByStr(List list,CommonNode rootNode,String index){ int count = 0; for(int i=0;i<list.size();i++){ String str = (String)list.get(i); StringTokenizer toc = new StringTokenizer(str,","); String t1 = toc.nextToken(); String t2 = toc.nextToken(); String t3 = toc.nextToken(); if(t1.equals(index)){ CommonNode nodeImpl = new CommonNode(); nodeImpl.setTitle(t3); rootNode.addChild(new Integer(count), nodeImpl); getTreeByStr(list,nodeImpl,t2); count++; } } return rootNode; } //init tree; private void loadTree(){ rootNode = new CommonNode(); String t1 = "0,1,a"; String t11 = "1,2,a1"; String t12 = "1,3,a2"; String t111 = "2,7,a11"; String t112 = "2,8,a12"; String t2 = "0,4,b"; String t21 = "4,5,b1"; String t22 = "4,6,b2"; List list = new ArrayList(); list.add(t1); list.add(t11); list.add(t12); list.add(t2); list.add(t21); list.add(t111); list.add(t112); rootNode = getTreeByStr(list,rootNode,"0"); } public TreeNode getTreeNode() { loadTree(); return rootNode; } }
CommonNode
public class CommonNode implements TreeNode { private static final long serialVersionUID = -5498990493803705085L; private Object data; private TreeNode parent; private boolean selected; private Object realData; private String title; private Object state1; private Object state2; private Map childrenMap = new LinkedHashMap(); public Object getData() { return data; } public TreeNode getChild(Object identifier) { return (TreeNode) childrenMap.get(identifier); } public void addChild(Object identifier, TreeNode child) { child.setParent(this); childrenMap.put(identifier, child); } public void removeChild(Object identifier) { TreeNode treeNode = (TreeNode) childrenMap.remove(identifier); if (treeNode != null) { treeNode.setParent(null); } } public void setData(Object data) { this.data = data; } public TreeNode getParent() { return parent; } public void setParent(TreeNode parent) { this.parent = parent; } public Iterator getChildren() { return childrenMap.entrySet().iterator(); } public boolean isLeaf() { return childrenMap.isEmpty(); } public boolean isSelected() { return selected; } public void setSelected(boolean selected) { this.selected = selected; } public Object getRealData() { return realData; } public void setRealData(Object realData) { this.realData = realData; } public String getType() { return "common"; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public Object getState1() { return state1; } public void setState1(Object state1) { this.state1 = state1; } public Object getState2() { return state2; } public void setState2(Object state2) { this.state2 = state2; } }
when i wanna load my tree,An Error Occurred:
/platform/log/tree.xhtml @19,87 nodeFace="#{item.type}": Bean: java.lang.String, property: type
Please help me,thanks ~~~