How can I select only a parent node (in a checkbox p:tree) without the children ? By default the children are also selected, what I want to avoid. So the problem is, that I can't select a parent node without selecting the children too.
Is there a solution? maybe with a method?
thanks!
here is my code:
<h:form id="selectCategoryForm">
<p:tree id="categoryTree" value="#{bean.categories}" var="node" selectionMode="checkbox" selection="#{bean.selectedCategories}" >
<p:treeNode>
<h:outputText value="#{node.path}" escape="false"/>
</p:treeNode>
</p:tree>
</h:form>
在树表上设置propagateSelectionDown="false"
,以禁止选择沿树传播
You can use:
<h:form id="selectCategoryForm">
<p:tree id="categoryTree" value="#{bean.categories}" var="node" selectionMode="checkbox" selection="#{bean.selectedCategories}" >
<p:ajax event="select" listener="#{bean.onNodeSelect}" update="@this"/>
<p:treeNode>
<h:outputText value="#{node.path}" escape="false"/>
</p:treeNode>
</p:tree>
</h:form>
and on the bean:
public void onNodeSelect(NodeSelectEvent event) {
TreeNode treeNode = event.getTreeNode();
TreeNode parentTreeNode = treeNode.getParent();
parentTreeNode.setSelected(true);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.