开发者

RichFaces rich:tree nodeFace type not assigned

I've a rich:tree in my JSF like so:

            <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

'#{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. 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:

In my backing开发者_运维技巧 bean (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:

            <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. 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. The nodeFace attribute determines which one of the nodes defined below will be rendered for each item.

You must populate your tree with nodes containing data of your custom type. Let's say your item looks like this:

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:

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜