如何使用Richfaces构建一个复选框树?

时间:2012-08-08 14:14:31

标签: java jsf java-ee tree richfaces

我想构建一个带有richfaces的复选框树。

我看到了here一个带有另一个jsf实现的示例。

我希望有类似的功能。

有可能吗?怎么样?

1 个答案:

答案 0 :(得分:1)

我不确定RichFaces能否为您提供帮助,但OmniFaces肯定是will

按照project page的说明将JAR添加到项目中,然后在bean中创建TreeModel的实现。

以下是展示中的示例,使用提供的ListTreeModel

private TreeModel<ExampleEntity> tree;

@PostConstruct
public void init() {
    tree = new ListTreeModel<ExampleEntity>();
    tree.addChild(new ExampleEntity(1L, "One"))
            .addChild(new ExampleEntity(2L, "Two")).getParent()
            .addChild(new ExampleEntity(3L, "Three")).getParent()
            .getParent()
        .addChild(new ExampleEntity(4L, "Four"))
            .addChild(new ExampleEntity(5L, "Five"));
}

然后,在您的XHTML页面上,您可以为树创建自定义标记,以下是使用带有复选框的HTML列表的示例:

 <o:tree id="tree" value="#{treeBean.tree}" var="exampleEntity" varNode="node">
    <o:treeNode>
        <ul>
            <o:treeNodeItem>
                <li>
                    <h:selectBooleanCheckbox value="#{exampleEntity.value}" />
                    <o:treeInsertChildren />
                </li>
            </o:treeNodeItem>
        </ul>
    </o:treeNode>
</o:tree>

然后,对于可折叠效果,您必须执行一些JavaScript,或重用其中一些that already exists