12 Replies Latest reply on Nov 29, 2012 11:04 AM by Emmanuel Koch

    unselecting tree node

    Nikola Ninovic Newbie



      Could anyone help me to perform unselecting of the tree node.

      I want to select node and then, when click on it again to deselect it



        • 1. unselecting tree node
          Lukáš Fryč Master

          Hello, the feature you are writing about seems will be implemented in scope of



          • 2. unselecting tree node
            Lukáš Fryč Master

            Though you should still be able to deselect tree node programatically using selection listener.

            • 3. unselecting tree node
              Ilya Shaikovsky Master

              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;").

              2) https://issues.jboss.org/browse/RF-10979

              • 4. unselecting tree node
                Nikola Ninovic Newbie

                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

                • 5. unselecting tree node
                  Ilya Shaikovsky Master

                  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.

                  • 6. unselecting tree node
                    Nikola Ninovic Newbie

                    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

                    • 7. unselecting tree node
                      Ilya Shaikovsky Master

                      doh.. probably could use original target and check if it's div with expand/collapse icon

                      • 8. Re: unselecting tree node
                        u j Novice



                        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-- 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.

                        Any idea?



                        • 9. Re: unselecting tree node
                          u j Novice

                          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!

                          • 10. Re: unselecting tree node
                            u j Novice

                            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?




                            • 12. Re: unselecting tree node
                              Emmanuel Koch Newbie

                              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?