我有这个 Primefaces 树:
JSF 代码
<h:form id="form">
<p:tree id="tree" value="#{TreeViewController.root}" var="node" dynamic="true" cache="true" animate="true"
selectionMode="single" selection="#{TreeViewController.selectedNode}" highlight="true">
<p:ajax event="select" listener="#{TreeViewController.onNodeSelect}" update=":form:outputComponent" />
<p:treeNode>
<h:outputText value="#{node}"/>
</p:treeNode>
</p:tree>
<p:outputPanel id="outputComponent">
<h:outputText value="#{TreeViewController.data}" />
</p:outputPanel>
</h:form>
托管豆
private TreeNode root;
private TreeNode selectedNode;
public TreeView() {
root = new DefaultTreeNode("Root", null);
TreeNode node0 = new DefaultTreeNode("Node 0", root);
TreeNode node1 = new DefaultTreeNode("Node 1", root);
TreeNode node2 = new DefaultTreeNode("Node 2", root);
TreeNode node3 = new DefaultTreeNode("Node 3", root);
TreeNode node4 = new DefaultTreeNode("Node 4", root);
TreeNode node00 = new DefaultTreeNode("Node 0.0", node0);
TreeNode node01 = new DefaultTreeNode("Node 0.1", node0);
TreeNode node02 = new DefaultTreeNode("Node 0.2", node0);
TreeNode node03 = new DefaultTreeNode("Node 0.3", node0);
TreeNode node04 = new DefaultTreeNode("Node 0.4", node0);
TreeNode node05 = new DefaultTreeNode("Node 0.5", node0);
TreeNode node06 = new DefaultTreeNode("Node 0.6", node0);
TreeNode node07 = new DefaultTreeNode("Node 0.7", node0);
TreeNode node08 = new DefaultTreeNode("Node 0.8", node0);
TreeNode node09 = new DefaultTreeNode("Node 0.9", node0);
TreeNode node10 = new DefaultTreeNode("Node 1.0", node1);
TreeNode node11 = new DefaultTreeNode("Node 1.1", node1);
TreeNode node000 = new DefaultTreeNode("Node 0.0.0", node00);
TreeNode node001 = new DefaultTreeNode("Node 0.0.1", node00);
TreeNode node010 = new DefaultTreeNode("Node 0.1.0", node01);
TreeNode node100 = new DefaultTreeNode("Node 1.0.0", node10);
}
public TreeNode getRoot() {
return root;
}
public String data;
public void onNodeSelect(NodeSelectEvent event) {
String node = event.getTreeNode().getData().toString();
data = node;
}
public String getData(){
return data;
}
public TreeNode getSelectedNode() {
return selectedNode;
}
public void setSelectedNode(TreeNode selectedNode) {
this.selectedNode = selectedNode;
}
我需要传递一个名为序列号的值,稍后将用于 SQL 查询以获取所选节点的信息。这个想法是为节点中的每个组件创建具有隐藏序列号的树。稍后此 SN 将用于从数据库中获取数据。如何为每个组件隐藏此 SN?现在我只能得到树节点的名称。