0

In my application I am using the p:tree in selectionMode:checkbox. Code is below:

<p:tree id="tree_permissoes" value="#{mBTipoUsuario.root}" var="node" selectionMode="checkbox" selection="#{mBTipoUsuario.selectedNodes} widgetVar="treeSingleWidget""> 
  <p:treeNode>
         <h:outputText value="#{node}"/> 
  </p:treeNode> 

I am having some problems to get the selected nodes in "mBTipoUsuario.selectedNodes" array. When the user click in a certain button I load the p:tree with some pre-selected nodes from the managed bean. Then, the user can select some other nodes, of their choice, in the p:tree and submit back to the managed bean. The problem is, in "mBTipoUsuario.selectedNodes" array, I just get the nodes that the user explicitly checked, but a miss the nodes that were pre-selected from the managed bean.

THE QUESTION IS: How to get both, the pre-selected nodes from the managed bean and those nodes explicitly selected by the user?

I have already tried to select the nodes I want to be pre-selected in the client side, as shown here: PrimeFaces Tree component, setting selected node from managed bean

But I have not any success. Can anyone help-me? Thanks.

Community
  • 1
  • 1

1 Answers1

2

I have solved my problem. Here is the solution for future readers. It is possible to check the Nodes from the client-side. This way is possible to recover all the nodes properly in the managed beans, even the the nodes pre-selected by the application, since we check them from Client-Side.

The solution for doing it is shown here: PrimeFaces Tree component, setting selected node from managed bean

But in our case, we don't want to select the nodes, we want to check them, so we can use the function 'toggleCheckboxNode' istead.

The final code is:

StringBuilder sb = new StringBuilder();
                        sb.append("PrimeFaces.widgets.treeSingleWidget.toggleCheckboxNode(");
                        sb.append("$(\"#frm_edit\\\\:tree_permissoes\\\\:");
                        sb.append(root.getChildren().get(i).getChildren().get(k).getRowKey());
                        sb.append("\")");
                        sb.append(", true)");
                        RequestContext.getCurrentInstance().execute(sb.toString());
Community
  • 1
  • 1