6

i have a p:treeTable in a form and a p:dialog in another form where from p:dialog i add data to the p:treeTable

on submit of h:commandButton of the dialog i add update of p:treeTable in orded to see the added node

The issue is that all expanded nodes the user has opened will all collapse

I found this question Avoiding the collapsing of p:treeTable after update which in the question he wrote solved but no answer or solution for his question

Community
  • 1
  • 1
bob-cac
  • 1,272
  • 2
  • 17
  • 35

3 Answers3

17

To avoid collapsing or expanding you have to mark your node on the java side as collapsed or expanded. To do that that just add some ajax calls and some listener methods.

JSF/Faces:

<p:tree ...>
    <p:ajax event="expand" listener="#{backing.nodeExpand}" />
    <p:ajax event="collapse" listener="#{backing.nodeCollapse}" />
...
</p:tree>

Java/Backing:

public void nodeExpand(NodeExpandEvent event) {
    event.getTreeNode().setExpanded(true);      
}

public void nodeCollapse(NodeCollapseEvent event) {
    event.getTreeNode().setExpanded(false);     
}
Paul Wasilewski
  • 9,762
  • 5
  • 45
  • 49
  • This does not work for multi-level treetable (i.e. you have to expand several nested nodes to get to leaf), is there a solution for this scenario? thanks. – wolf97084 May 08 '18 at 22:37
  • 2
    Update: I have found a solution. I have to keep track of expanded nodes and expand those after root node updated. – wolf97084 May 10 '18 at 15:49
1

According to PrimeFaces Tree Events Showcase you forgot to use the update statement.

Cerbenus
  • 213
  • 3
  • 11
1

If you try call any action or actionListener inside the tree you need expend all node and parents, with you don't do you this only don't work and don't show any error.

node.setExpanded(true);
node.getParent().setExpanded(true);
Pang
  • 9,564
  • 146
  • 81
  • 122
Camila Macedo
  • 857
  • 7
  • 10