我從Primefaces Showcase Tree Checkbox Selection本例中沒有選擇Primefaces樹頂父節點:在選擇孩子的
public TreeCheckboxBean() {
root2 = new CheckboxTreeNode("Root", null);
TreeNode node0 = new CheckboxTreeNode("Node 0", root2);
TreeNode node1 = new CheckboxTreeNode("Node 1", root2);
TreeNode node2 = new CheckboxTreeNode("Node 2", root2);
TreeNode node00 = new CheckboxTreeNode("Node 0.0", node0);
TreeNode node01 = new CheckboxTreeNode("Node 0.1", node0);
TreeNode node10 = new CheckboxTreeNode("Node 1.0", node1);
TreeNode node11 = new CheckboxTreeNode("Node 1.1", node1);
TreeNode node000 = new CheckboxTreeNode("Node 0.0.0", node00);
TreeNode node001 = new CheckboxTreeNode("Node 0.0.1", node00);
TreeNode node010 = new CheckboxTreeNode("Node 0.1.0", node01);
TreeNode node100 = new CheckboxTreeNode("Node 1.0.0", node10);
}
public TreeNode[] getSelectedNodes() {
return selectedNodes;
}
public void setSelectedNodes(TreeNode[] selectedNodes) {
this.selectedNodes = selectedNodes;
}
public void displaySelectedMultiple() {
if(selectedNodes != null && selectedNodes.length > 0) {
StringBuilder builder = new StringBuilder();
for(TreeNode node : selectedNodes) {
builder.append(node.getData().toString());
builder.append("<br />");
}
FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "Selected", builder.toString());
FacesContext.getCurrentInstance().addMessage(null, message);
}
}
從那裏我檢查孩子節點0.1,節點0.1.0,節點1.1。當我點擊顯示選定的按鈕時,通知僅顯示上述節點爲選定狀態。
有沒有什麼辦法可以將節點0和節點1也包括在內?
因此,這將成爲節點0,節點0.1,節點0.1.0,節點1,節點1.1
FYI:我使用Primefaces 4,JSF 2.1.26。
在這裏和那裏稍微調整之後,迭代節點從父級到父級集合selected = true,正在工作。只需使用此方法的其他信息,您仍然需要刷新/更新樹組件本身。謝謝:) –