📅  最后修改于: 2021-01-08 12:41:09             🧑  作者: Mango
该组件用于创建分层树。它使用< rich:treeNode >作为子组件。
我们可以根据需要创建定制树。 RichFaces提供了所有可用的组件来相应地创建树。
它需要value属性绑定数据模型以创建树。数据模型必须是org.richfaces.model.TreeNode接口, org.richfaces.model.TreeDataModel接口或javax.swing.tree.TreeNode接口。
下表包含TreeNode的Style类和相应的外观参数。
Class | Function | Skin Parameters | Mapped CSS properties |
---|---|---|---|
.rf-trn | It is used to define styles for a tree node. | generalFamilyFont generalSizeFont |
font-family font-size |
.rf-trn-lbl | It is used to define styles for a tree node label. | No skin parameters. | |
.rf-trn-cnt | It is used to define styles for tree node content. | No skin parameters. | |
.rf-trn-sel | It is used to define styles for a selected tree node. | additionalBackgroundColor | background |
.rf-trn-ldn | It is used to define styles for a tree node when it is loading. | additionalBackgroundColor | background |
.rf-trn-hnd | It is used to define styles for a tree node handle. | No skin parameters. | |
.rf-trn-hnd-lf | It is used to define styles for the handle of a leaf node. | No skin parameters. | |
.rf-trn-hnd-colps | It is used to define styles for the handle of a collapsed node. | No skin parameters. | |
.rf-trn-hnd-exp | It is used to define styles for the handle of an expanded node. | No skin parameters. | |
.rf-trn-hnd-ldn-fct | It is used to define styles for the loading facet of a tree node handle. | No skin parameters. | |
.rf-trn-ico | It is used to define styles for tree node icon. | No skin parameters. | |
.rf-trn-ico-lf | It is used to define styles for the icon of a leaf node. | No skin parameters. | |
.rf-trn-ico-colps | It is used to define styles for the icon of a collapsed node. | No skin parameters. | |
.rf-trn-ico-exp | It is used to define styles for the icon of an expanded node. | No skin parameters. | |
.rf-trn-ico-cst | It is used to define styles for a custom node icon. | No skin parameters. |
在下面的示例中,我们正在实现< rich:tree >组件。本示例包含以下文件。
// rich-tree.xhtml
Rich Tree
// Tree.java
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import org.richfaces.model.TreeNodeImpl;
@ManagedBean
@RequestScoped
public class Tree extends TreeNodeImpl {
private Tree stationRoot;
private Tree rootNodes;
private Object data;
public Tree() {
super();
}
public Tree(boolean leaf, Object data) {
super(leaf);
this.data = data;
}
public Object getData() {
return data;
}
@Override
public String toString() {
return super.toString() + ">>" + data;
}
public Tree getRootNodes() {
if (rootNodes == null) {
String[] author_collection = {"Ravindra Nath Tagore - Geetanjali",
"David Bowie - Let's Dance",
"Paulo Coelho - Alchemist",
"Kim Carnes - Bette Davis Eyes",
"KC & the Sunshine Band - Give It Up"};
stationRoot = new Tree(false, "Books Collection");
for (int i = 0; i < author_collection.length; i++) {
Tree child = new Tree(true, author_collection[i]);
stationRoot.addChild(i, child);
}
rootNodes = new Tree();
rootNodes.addChild(0, stationRoot);
}
return rootNodes;
}
}
输出:
扩展根树后,它将显示所有树节点,如下所示。