TreeTable multiple selection setter not called

UI Components for JSF
Post Reply
User avatar
mike5
Posts: 9
Joined: 12 Mar 2015, 15:25

19 Jul 2015, 19:34

Hi.

I'm using a Tree Table and I wan't to catch multiple selection with a shift key. Since the select even't doesn't work, I tried doing the required processing in the setter.

But the problem is that the setter only seems to get called if I'm selecting a single node or adding nodes using the control key. If I use the shift key, the UI displays multiple selected nodes, but the setter does not get called - tested in the debugger.

Please, can someone tell me how to catch the shift-selection in the managed bean? How does the back-end array of TreeNodes get set if not through the setter?

Thanks in advance and best regards, Miha
PrimeFaces 5.2
JSF 2.1
WildFly 8.2

User avatar
mike5
Posts: 9
Joined: 12 Mar 2015, 15:25

20 Jul 2015, 08:18

And "teh codes":

Code: Select all

<p:treeTable id="tree" value="#{controller.rootNode}" var="node" 
        selectionMode="multiple" selection="#{controller.selectedNodes}" 
        scrollable="true" scrollWidth="auto" rowStyleClass="treeRows" 
        style="width: 30em;" widgetVar="hierarchyWidget">
    <p:ajax event="select" update=":form:relationsTable :form:deleteButton" 
        oncomplete="arrangeUI();" />
    <p:ajax event="unselect" update=":form:relationsTable :form:deleteButton" 
        oncomplete="arrangeUI();" />
    <p:ajax event="expand" listener="#{controller.onContainsExpand}" />

    <p:column id="name" headerText="Name">
        <h:outputText value="#{node.name}" title="#{node.description}" />
    </p:column>
</p:treeTable>

Code: Select all

public void setSelectedNodes(TreeNode[] nodes) {
    this.selectedNodes = nodes;   // breakpoint ignored for doing Shift-select
}
Br, Miha
PrimeFaces 5.2
JSF 2.1
WildFly 8.2

Chasy Adler
Posts: 3
Joined: 10 Dec 2015, 10:39

14 Dec 2015, 16:18

You can fix it as suggested when the same issue appeared in p:dataTable. (http://forum.primefaces.org/viewtopic.php?f=3&t=24543)

Just override PrimeFaces javascript function selectNodesInRange.

Code: Select all

PrimeFaces.widget.TreeTable.prototype.selectNodesInRange = function(node) {
	if (this.cursorNode) {
		this.unselectAllNodes();

		var currentNodeIndex = node.index(),
		cursorNodeIndex = this.cursorNode.index(),
		startIndex = (currentNodeIndex > cursorNodeIndex) ? cursorNodeIndex : currentNodeIndex,
		endIndex = (currentNodeIndex > cursorNodeIndex) ? (currentNodeIndex + 1) : (cursorNodeIndex + 1),
		nodes = this.tbody.children();

		for(var i = startIndex ; endIndex > i; i++) {
			var lastRow = endIndex - 1 == i ? true : false;
			this.selectNode(nodes.eq(i), !lastRow);
		}
	} 
	else {
		this.selectNode(node);
	}
};
(I had another problem because I set the selected node in the first load of the page in my backing bean

Code: Select all

if (!root.getChildren().isEmpty()) {
	TreeNode node = root.getChildren().get(0);
	node.setSelected(true);
}
So only after I selected a node without the shift key this line in the code: if (this.cursorNode) was always undefined so I added this too:

Code: Select all

PrimeFaces.widget.TreeTable.prototype.cursorNode = $("[id$='XXXX_0']"); <- the first row in the dataTable
)

Good luck!!
Last edited by Chasy Adler on 22 Dec 2015, 10:37, edited 1 time in total.

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 55 guests