Though you should still be able to deselect tree node programatically using selection listener.
Lukas is right there is:
UITree.setSelection(collection). it should be passed with the rowKey's of selected nodes. (actually while multi selection is not implemented with single rowKey). Or in your case with null value or empty collection (still need to try)
But b.t.w. I found some problems there:
1) when you clicking the node second time it rises ajax request also. And probably fires selectionChangeListener. But actually it differs from 3.3.x and I'm not sure than now it's more properly behaves. Actually there were no selection change in case of subsequent clicks onm the same node, so event name slightly confuses. But as much users asked about that in 3.3.x - seems like really valid. But we need to document that. (And need to ensure that we will provide the way to cancel the request on subsequent clicks on the same treeNode in case selection not really changes. At least using something like onbeforeselectionchange="if (event.oldSelection...) return false;").
So, the problem is that I'm using 3.3.3 version.
As I can see there is no possibility to fire selection event when I click on already selected item
Ah.. yup.. in 3.3.x you should turn built-in selection processing off. And use a4j:support on onclick instead. And use advisors for selection/expansion managing.
Yes, but the problem still exists .
I already tried onclick with a4j:support, but the problem is that the onclick method is invoked even if I expand/collapse tree node.
Is there a posibility to know what action is fired, node click or node expand/collapse
doh.. probably could use original target and check if it's div with expand/collapse icon
in RichFaces 4 I try to unselect a node in a treeSelectionChangeListener with setSelection(null).
Furthermore, for the selected node I change the rendered attribute to false. In this case I get:
20:00:32,894 SEVERE [org.richfaces.log.Context] (http--127.0.0.1-8080-3) null: java.lang.NullPointerException
at org.richfaces.renderkit.TreeRendererBase.encodeSelectionStateInput(TreeRendererBase.java:133) [richfaces-components-ui-4.0.0-20110322.220419-243.jar:]
at org.richfaces.renderkit.html.TreeRenderer.encodeEnd(TreeRenderer.java:145) [richfaces-components-ui-4.0.0-20110322.220419-243.jar:]
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875) [jboss-jsf-api_2.0_spec-1.0.0.Final.jar:2.1.2-FCS]
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1763) [jboss-jsf-api_2.0_spec-1.0.0.Final.jar:2.1.2-FCS]
at org.richfaces.context.ExtendedPartialViewContextImpl$RenderVisitCallback.visit(ExtendedPartialViewContextImpl.java:514) [richfaces-core-impl-4.0.0-20110325.220425-378.jar:]
at org.richfaces.context.BaseExtendedVisitContext.invokeVisitCallback(BaseExtendedVisitContext.java:337) [richfaces-core-impl-4.0.0-20110325.220425-378.jar:]
at org.richfaces.component.UIDataAdaptor.visitTree(UIDataAdaptor.java:1235) [richfaces-components-ui-4.0.0-20110322.220419-243.jar:]
I also tried to select another node or set an empty collection. Nothing helps. The original selection is maintained and leads to the exception.
Update: I have realized that setSelection(null) or setSelection(anotherNode) does NOT unselect the selected node, at least within a selection change listener.
If you then click again the same node, no change event is generated.
Any help, please!
I found a workaround: you can throw a AbortProcessingException, so the selection is not restored. The drawback is that it logs a SEVERE error stack trace. Not very nice. Isn't there a way to gently deselect the node?
I exacly have the same problem, using RF4.2.3. I want to programatically unselect my node.
I binded the tree component in my javaclass (UITree)
UITree.setSelection(null) do not work.
Do you have any workaround here?