[英]RichFaces rich:tree nodeFace type not assigned
I've a rich:tree
in my JSF like so: 我的JSF中有一个
rich:tree
,就像这样:
<rich:tree value="#{MyBacking.treeNodes}" var="item"
nodeFace="#{item.type}">
<rich:treeNode type="folder"
<h:outputText value="#{item.folder}" />
</rich:treeNode>
<rich:treeNode type="file"
<h:outputText value="#{item.contfile}" />
</rich:treeNode>
</rich:tree>
and the java runtime error 和Java运行时错误
'#{item.type}' Property 'type' not found on type java.lang.String
But I've looked at the javadoc for org.richfaces.model.TreeNodeImpl
and there's no mention of a method to assign a type to a tree node. 但是我已经看过
org.richfaces.model.TreeNodeImpl
的javadoc了,没有提到将类型分配给树节点的方法。 How is this done? 怎么做?
EDIT I have modified the code as per the supplied answer. 编辑我已经按照提供的答案修改了代码。 Although it feels right, my tree is now being ignored.
尽管感觉不错,但我的树现在被忽略了。 The java looks like this:
Java看起来像这样:
In my backing bean (MyBacking): 在我的后备豆(MyBacking)中:
public TreeNodeImpl<LogTreeItem> getTreeNodes() {
TreeNodeImpl<LogTreeItem> rootNode = new TreeNodeImpl<LogTreeItem>();
LogTreeItem rootItem = new LogTreeItem();
rootItem.setType("folder");
rootItem.setName("folderName");
rootNode.setData(rootItem);
return rootNode;
}
item class: 项目类别:
public class LogTreeItem {
private String type;
private String name;
public String getType() {
return type;
}
public void setType(String t) {
type = t;
}
public String getName() {
return name;
}
public void setName(String n) {
name = n;
}
}
JSF snippet thus is now: 因此,JSF片段现在为:
<rich:tree value="#{MyBacking.treeNodes}" var="item" nodeFace="#{item.type}">
<rich:treeNode type="folder">
<h:outputText value="#{item.name}" />
</rich:treeNode>
</rich:tree>
All I'm trying to do at this point is get a tree recognised. 在这一点上,我要做的只是识别一棵树。 As I'm only creating a tree with a rootNode, I was expecting a one node tree output, but instead I'm seeing nothing at all.
因为我只创建带有rootNode的树,所以我期望输出一个节点树,但是却什么也没看到。 I know I'm close but I just cannot see what tweak would bring it to life.
我知道我已经接近了,但是我看不出有什么调整可以使它栩栩如生。
Thanks a lot 非常感谢
It appears that your item
is of type String
. 您的
item
似乎是String
类型的。 The nodeFace
attribute determines which one of the nodes defined below will be rendered for each item
. nodeFace
属性确定将为每个item
呈现以下定义的哪个节点。
You must populate your tree with nodes containing data of your custom type. 您必须用包含自定义类型数据的节点填充树。 Let's say your
item
looks like this: 假设您的
item
看起来像这样:
public class Item {
private String type; //getter+setter
private String folder; //getter+setter
private String contfile; //getter+setter
}
Then treeNodes
should actually be rootNode
, and must look like this: 然后,
treeNodes
实际上应该是rootNode
,并且必须看起来像这样:
rootNode = new TreeNodeImpl<Item>();
for (some loop here) {
TreeNode<Item> node = new TreeNodeImpl<Item>();
Item item = ..; //get or create the item;
node.setData(item);
node.setParent(rootNode);
rootNode.addChild("someIdentifier", node);
}
I'd suggest checking out richfaces demo sources to see how it is implemented there. 我建议您查看richfaces演示源,以了解如何在那里实现。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.