TreeTable - collapsed state update

UI Components for JSF
Post Reply
vddv
Posts: 10
Joined: 05 Jun 2012, 13:39

30 Jul 2012, 10:09

Hello all,

I'm dealing with a problem with my TreeTable concerning the server-side saving of expand-state of nodes when collapsing.
First of all, here's the snippet:

Code: Select all

					<p:treeTable value="#{ctrl.treeRoot}" var="row" id="myTree" selectionMode="single" selection="#{ctrl.selectedNode}">
						<p:ajax event="expand" process="@this" />
						<p:ajax event="collapse" process="@this" />
						<p:column>
							<h:outputText value="#{row.title}" />
						</p:column>
					</p:treeTable>
I want to use the ajax-event "collapse" to trigger an update of the TreeNodes for saving their new "collapsed" state. It works with "expand" (actually I don't know if I need this ajax binding at all), but not for collapsing.

To see that the collapsed state is not set on server-side, one can change the second p:ajax tag to the following:

Code: Select all

						<p:ajax event="collapse" process="@this" update="myTree" />
This will cause the row to collapse at first and then it is expanded again after the update is processed. Very weird behaviour.

So, every time I use update="myTree" from any other UI element, the tree gets all nodes expanded that the user ever(!) opened earlier.
I want, that on collapsing a row, the corresponding TreeNode gets the property setExpanded(false) set.


Is there any workaround for this or am I doing something wrong?

Technical info: Primefaces 3.3.1, MyFaces 2.1.7 with Facelets, Tomcat 6.0

I appreciate any help on this. Thanks in advance!

vddv
Posts: 10
Joined: 05 Jun 2012, 13:39

30 Jul 2012, 13:04

After some experiments, I just managed to get the collapsed state saved in my TreeNode objects on server-side using a listener:

Code: Select all

					<p:treeTable value="#{ctrl.treeRoot}" var="row" id="myTree" selectionMode="single" selection="#{ctrl.selectedNode}">
						<p:ajax event="collapse" listener="#{ctrl.onNodeCollapse}" />
						<p:column>
							<h:outputText value="#{row.title}" />
						</p:column>
					</p:treeTable>
With my controller's listener looking simply like this:

Code: Select all

    public void onNodeCollapse(NodeCollapseEvent event) {
    	if (event != null && event.getTreeNode() != null) {
    		event.getTreeNode().setExpanded(false);
    	}
    }  
This does the trick, although I think the framework should do this itself to avoid including the p:ajax line in every p:treeTable I use.

cookiemonster
Posts: 17
Joined: 16 Dec 2011, 15:40

15 Nov 2012, 18:14

answer is very useful. thanks.

adw33456
Posts: 2
Joined: 03 Apr 2014, 01:47

22 Jan 2015, 02:07

This saved my butt today! Appreciate the fix and the code.

bartelski
Posts: 1
Joined: 13 May 2015, 23:28

04 Sep 2015, 23:43

Thanks for that. Same issue here.

I agree. It seems to me that expand/collapse state should be set by primefaces automatically in the same way that select is.

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 53 guests