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
TreeTable multiple selection setter not called
And "teh codes":
Br, Miha
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
}
PrimeFaces 5.2
JSF 2.1
WildFly 8.2
JSF 2.1
WildFly 8.2
-
- Posts: 3
- Joined: 10 Dec 2015, 10:39
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.
(I had another problem because I set the selected node in the first load of the page in my backing bean
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:
)
Good luck!!
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);
}
};
Code: Select all
if (!root.getChildren().isEmpty()) {
TreeNode node = root.getChildren().get(0);
node.setSelected(true);
}
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.
-
- Information
-
Who is online
Users browsing this forum: No registered users and 55 guests