1 2 Previous Next 21 Replies Latest reply on Apr 10, 2014 5:10 AM by jjakub

    RF 4: rich:tree selectionChangeListener not invoked

    mtle

      Hi,

       

      I'm using RF4 via maven with

      <org.richfaces.bom.version>4.0.0.Final</org.richfaces.bom.version>

      having trouble with the new rich:tree. The concept and the examples in the showcase look really simple (much better than in RF3), but it's not working for me. The tree is displayed, I can expand and collapse nodes, but the selection does not work.

      Here is my xhtml:

       

       

      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
          xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:a4j="http://richfaces.org/a4j" xmlns:rich="http://richfaces.org/rich">
      
      <body>
      <ui:composition>
          <h:form prependId="false">
              <rich:tree id="mBeanTree" value="#{treeBuilder.nodes}" var="node" toggleType="client" selectionType="ajax" selectionChangeListener="#{treeBean.processTreeSelectionChange}" nodeType="#{node.nodeType}">
                  <rich:treeNode type="SERVER" iconExpanded="/images/tree/server.png" iconCollapsed="/images/tree/server.png">
                      #{node.displayName}"
                  </rich:treeNode>
              </rich:tree>
          </h:form>
      </ui:composition>
      </body>
      </html>
      

       

      treeBean is sessionscoped and looks like this:

       

       

      public class TreeBean implements Serializable, TreeSelectionChangeListener {
      
          private static final long serialVersionUID = 1L;
      
          private TreeNode currentSelection = null;
      
          public TreeNode getCurrentSelection() {
              return currentSelection;
          }
      
          public void setCurrentSelection(TreeNode currentSelection) {
              this.currentSelection = currentSelection;
          }
      
          /* (non-Javadoc)
           * @see org.richfaces.event.TreeSelectionChangeListener#processTreeSelectionChange(org.richfaces.event.TreeSelectionChangeEvent)
           */
          public void processTreeSelectionChange(TreeSelectionChangeEvent selectionChangeEvent) throws AbortProcessingException {
              System.out.println("change");
              // considering only single selection
              List<Object> selection = new ArrayList<Object>(selectionChangeEvent.getNewSelection());
              Object currentSelectionKey = selection.get(0);
              UITree tree = (UITree) selectionChangeEvent.getSource();
      
              Object storedKey = tree.getRowKey();
              tree.setRowKey(currentSelectionKey);
              currentSelection = (TreeNode) tree.getRowData();
              tree.setRowKey(storedKey);
          }
      }
      

       

      I also tried it with TreeBean not implementing TreeSelectionChangeListener - not working either.

       

      The processTreeSelectionChange method is not invoked and the selcted node is not marked as selected (gray background). However, if I change selectionType of the rich:tree from ajax to client, the visual selection works (gray background) but the processTreeSelectionChange method is still not invoked.

      Does anybody have an idea whats wrong?

       

      Many thanks in advance!

       

      And by the way: The documentation says, that the selectionType attribute can also be "server", but this leads to an illegal argument exception.

        • 1. RF 4: rich:tree selectionChangeListener not invoked
          ilya_shaikovsky

          unfortunatelly can't see much difference with

          http://richfaces-showcase.appspot.com/richfaces/component-sample.jsf?demo=tree&skin=blueSky

          but it works for me...

          • 2. Re: RF 4: rich:tree selectionChangeListener not invoked
            mtle

            Thanks for your quick reply

             

            I was afraid of that...

            Strange thing is: If I change the value of the selectionChangeListener attribute to treeBeanBlabla.processTreeSelectionChange or treeBean.processTreeSelectionChangeblabla no error is thrown, as it would if I change another attribute. Its almost like the component doesn't know the selectionChangeListener attribute. Its ignored.

            I also tried

            <rich:treeSelectionChangeListener id="#{treeBean}" />

            but this doesn't work either.

            • 3. RF 4: rich:tree selectionChangeListener not invoked
              nbelaevski

              Hi,

               

              Correct name for attribute is 'treeSelectionChangeListener', please try that.

              • 4. Re: RF 4: rich:tree selectionChangeListener not invoked
                mtle

                Hi Nick,

                 

                I tried, but without success. The attribut is also ignored. It doesn't matter, if set the value to #{treeBean} or #{treeBeanblabla}.

                For fun, I tried out the toggleListener which also doesn't work and is ignored.

                Could it be, that the ajax event is not fired at all and that's why the el is not evaluated at all?

                • 5. Re: RF 4: rich:tree selectionChangeListener not invoked
                  nbelaevski

                  Entrirely possible; do you see Ajax request in Firebug?

                   

                  BTW, does anything change if you set prependId="true"?

                  • 6. Re: RF 4: rich:tree selectionChangeListener not invoked
                    fpr69

                    Hi-  I'm having the same issue, where the treeSelectionChangeListener is not invoking the method on my managed bean. The tree renders nicely and the nodes expand and collapse correctly; however, when select a leaf node or any node, no action is taken and I've confirmed that my listener method is never invoked.  Any help is greatly appreciated.

                     

                    Here is some of the code:

                     

                    .xhtml file:

                     

                    This code is wrapped by a single <h:form>.

                     

                    <rich:tree styleClass="treeAlpha"  id="treeSource" nodeType="#{node.type}" 
                        treeSelectionChangeListener="alphaIndexController.selectionChanged" 
                        var="node" value="#{alphaIndexController.rootNodes}" toggleType="client"
                        selectionType="ajax" iconCollapsed="/policy/resources/img/tree_node.jpg" 
                        iconExpanded="/policy/resources/img/tree_node_e.jpg" 
                        rendered="#{not empty alphaIndexController.rootNodes}">
                    
                        <rich:treeNode type="Level1">
                            #{node.name}
                        </rich:treeNode>
                        <rich:treeNode type="Level2">
                            #{node.name}
                        </rich:treeNode>
                    
                    </rich:tree>
                    
                    

                     

                    managed bean file:

                     

                     

                    @ManagedBean(name = "alphaIndexController")
                    @SessionScoped
                    public class AlphaIndexController implements Serializable {
                    ....
                    ....
                    
                        public void selectionChanged(TreeSelectionChangeEvent selectionChangeEvent) {
                            List<Object> selection = new ArrayList<Object>(selectionChangeEvent.getNewSelection());
                            Object currentSelectionKey = selection.get(0);
                            UITree tree = (UITree) selectionChangeEvent.getSource();
                    
                            Object storedKey = tree.getRowKey();
                            tree.setRowKey(currentSelectionKey);
                            currentSelection = (TreeNode) tree.getRowData();
                            tree.setRowKey(storedKey);
                        }
                    ....
                    ....
                    
                    
                    • 7. Re: RF 4: rich:tree selectionChangeListener not invoked
                      mtle

                      Hi,

                       

                      prependID="true" doesn't change anything.

                      Firebug shows me a POST-Request, and the answer to this request is:

                       

                       

                      <partial-response>
                           <changes>
                                <update id="j_idt10:mBeanTree__SELECTION_STATE"><![CDATA[<input type="hidden" name="j_idt10:mBeanTree__SELECTION_STATE" id="j_idt10:mBeanTree__SELECTION_STATE" class="rf-tr-sel-inp" value="" />]]></update>
                                <update id="javax.faces.ViewState"><![CDATA[1662711449184295576:-7115381071575210838]]></update>
                           </changes>
                           <extension id="org.richfaces.extension">
                                <complete>RichFaces.$("j_idt10:mBeanTree").__updateSelectionFromInput();;</complete>
                           </extension>
                      </partial-response>
                      
                      • 8. Re: RF 4: rich:tree selectionChangeListener not invoked
                        mtle

                        No ideas? Am I missing someting in the web.xml?

                         

                        It looks like this:

                         

                         

                        <?xml version="1.0" encoding="UTF-8"?>
                        <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                            xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
                            <display-name>Sample RichFaces 4 Application</display-name>
                            <context-param>
                                <param-name>javax.faces.PROJECT_STAGE</param-name>
                                <param-value>Development</param-value>
                            </context-param>
                            <context-param>
                                <param-name>javax.faces.SKIP_COMMENTS</param-name>
                                <param-value>true</param-value>
                            </context-param>
                            <servlet>
                                <servlet-name>Faces Servlet</servlet-name>
                                <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
                                <load-on-startup>1</load-on-startup>
                            </servlet>
                            <servlet-mapping>
                                <servlet-name>Faces Servlet</servlet-name>
                                <url-pattern>*.xhtml</url-pattern>
                            </servlet-mapping>
                            <session-config>
                                <session-timeout>30</session-timeout>
                            </session-config>
                        
                            <mime-mapping>
                                <extension>ecss</extension>
                                <mime-type>text/css</mime-type>
                            </mime-mapping>
                            <welcome-file-list>
                                <welcome-file>index.xhtml</welcome-file>
                            </welcome-file-list>
                            <login-config>
                                <auth-method>BASIC</auth-method>
                            </login-config>
                        </web-app>
                        
                        • 9. Re: RF 4: rich:tree selectionChangeListener not invoked
                          jackjackrus

                          I have totaly the same problem. Tree node not even highlited on "ajax"-type selection.

                           

                          For example here is the code:

                          <h:form id="form">
                                    <rich:tree id="tree" value="#{testTree.testListRoot}" var="node"   toggleType="client" selectionType="ajax"/>
                          </h:form>
                          

                           

                          Here is a4j:log output when I click on some node:

                          debug[16:50:09.430]: New request added to queue. Queue requestGroupingId changed to j_idt8:j_idt9
                          debug[16:50:09.430]: Queue will wait 0ms before submit
                          debug[16:50:09.431]: richfaces.queue: will submit request NOW
                          info [16:50:09.433]: Received 'begin' event from <div id=j_idt8:j_idt9 class="rf-tr" ...>
                          info [16:50:09.531]: Received 'beforedomupdate' event from <div id=j_idt8:j_idt9 class="rf-tr" ...>
                          debug[16:50:09.533]: Server returned responseText: <?xml version='1.0' encoding='ISO-8859-1'?> <partial-response><changes><update id="javax.faces.ViewState"><![CDATA[318877617883190187:8098339558020226768]]></update></changes></partial-response>
                          info [16:50:09.535]: Listing content of response changes element:
                          Element update for id=javax.faces.ViewState
                          <update id="javax.faces.ViewState"><![CDATA[318877617883190187:8098339558020226768]]></update>
                          
                          debug[16:50:09.537]: richfaces.queue: ajax submit successfull
                          debug[16:50:09.537]: richfaces.queue: Nothing to submit
                          info [16:50:09.539]: Received 'success' event from <div id=j_idt8:j_idt9 class="rf-tr" ...>
                          info [16:50:09.540]: Received 'complete' event from <div id=j_idt8:j_idt9 class="rf-tr" ...>
                          

                           

                          Especcially interesting is "id=javax.faces.ViewState" is thats ok?

                           

                          What is the problem?

                          • 10. Re: RF 4: rich:tree selectionChangeListener not invoked
                            nbelaevski

                            Valeriy,

                             

                            How does testTree bean look like and what is its scope?

                            • 11. Re: RF 4: rich:tree selectionChangeListener not invoked
                              fpr69

                              Nick- I've been working on the same issue for over a week with no success.  Here is another tree of many that I need to implement throughout my application.  Any help is greatly appreciated! 

                               

                              The tree loads nicely and all my nodes collapse/expand correctly, but my listener method is never invoked (confirmed with debug statements).

                               

                               

                              <!-- .xhtml -->
                              
                                    <rich:tree id="treeSource" nodeType="#{node.type}" var="node" 
                                             value="#{gemcmController.rootNodesSource}" toggleType="client" 
                                      selectionType="ajax"  
                                      treeSelectionChangeListener="#{gemcmController.selectionChanged}"
                                      iconCollapsed="/policy/resources/img/tree_node.jpg" 
                                      iconExpanded="/policy/resources/img/tree_node_e.jpg" 
                                      render="#{not empty gemcmController.rootNodesSource}">
                                      <rich:treeNode type="SourceCode">
                                          #{node.name}
                                      </rich:treeNode>
                                      <rich:treeNode type="Scenario">
                                          #{node.name}
                                      </rich:treeNode>
                                      <rich:treeNode type="TargetCode">
                                          #{node.name}
                                      </rich:treeNode>
                                  </rich:tree>
                              
                              //Bean
                              .....    
                              @ManagedBean(name = "gemcmController")
                              @SessionScoped
                              public class GemcmController implements Serializable {
                              .....
                              .....
                              
                              
                              
                                  public void selectionChanged(TreeSelectionChangeEvent selectionChangeEvent) {
                                      // considering only single selection
                                      List<Object> selection = new ArrayList<Object>(selectionChangeEvent.getNewSelection());
                                      Object currentSelectionKey = selection.get(0);
                                      UITree tree = (UITree) selectionChangeEvent.getSource();
                              
                                      Object storedKey = tree.getRowKey();
                                      tree.setRowKey(currentSelectionKey);
                                  }
                              
                              
                              
                              • 12. Re: RF 4: rich:tree selectionChangeListener not invoked
                                jackjackrus

                                The problem was not the scope, but my TreeNode class. 

                                 

                                Instead of implementing TreeNode I use TreeNodeImpl. Maybe it is broken, or maybe I've just used it the wrong way.

                                 

                                Anyway, this  code doesn't work for me:

                                @ManagedBean
                                @SessionScoped
                                public class TestTree implements Serializable{ 
                                
                                    int key = 1;
                                
                                    public class TestTreeNode extends TreeNodeImpl{
                                
                                          Object wrapped;
                                          public Object getWrapped() {
                                              return wrapped;
                                          }
                                
                                
                                          @Override
                                          public String toString() {
                                              return wrapped.toString();
                                          }
                                
                                
                                          public TestTreeNode(Object toWrap, TreeNode root){
                                              wrapped=toWrap;
                                              root.addChild(key++, this); //sic!
                                          }
                                
                                          public TestTreeNode() {
                                              Logger.getLogger(this.getClass()).debug("init");
                                          } 
                                    }
                                
                                
                                    private TestTreeNode testTreeRoot;
                                    public TreeNode getTestListRoot(){
                                        return testTreeRoot;
                                    }
                                
                                
                                    public void selectionChanged(TreeSelectionChangeEvent event) throws AbortProcessingException {
                                          Logger.getLogger(this.getClass()).debug("something is selected!");
                                    }
                                
                                
                                    public TestTree() {
                                          testTreeRoot = new TestTreeNode();
                                          new TestTreeNode("test-1", testTreeRoot);
                                          new TestTreeNode("test-2", testTreeRoot);
                                          new TestTreeNode("test-3", testTreeRoot);
                                    } 
                                
                                }
                                

                                The problem was the key parametr of the TreeNodeImpl  addChild method.  As I sad before nodes had not even got highlighted.

                                 

                                 

                                I change my key type to String and it gets work!

                                @ManagedBean
                                @SessionScoped
                                public class TestTree implements Serializable{
                                
                                
                                    String key = "a";//For example String
                                
                                
                                    public class TestTreeNode extends TreeNodeImpl{
                                
                                          Object wrapped;
                                          public Object getWrapped() {
                                              return wrapped;
                                          } 
                                
                                          @Override
                                          public String toString() {
                                              return wrapped.toString();
                                          } 
                                
                                          public TestTreeNode(Object toWrap, TreeNode root){
                                              wrapped=toWrap;
                                              root.addChild(key+="a", this);
                                          }
                                
                                          public TestTreeNode() {
                                              Logger.getLogger(this.getClass()).debug("init");
                                          } 
                                    }
                                
                                
                                    private TestTreeNode testTreeRoot;
                                    public TreeNode getTestListRoot(){
                                        return testTreeRoot;
                                    }
                                
                                    public void selectionChanged(TreeSelectionChangeEvent event) throws AbortProcessingException {
                                          Logger.getLogger(this.getClass()).debug("something is selected!");
                                    }
                                
                                    public TestTree() {
                                          testTreeRoot = new TestTreeNode();
                                          new TestTreeNode("test-1", testTreeRoot);
                                          new TestTreeNode("test-2", testTreeRoot);
                                          new TestTreeNode("test-3", testTreeRoot);
                                    } 
                                }
                                

                                Now nodes are highlighting, its cool, but  treeSelectionChangeListener (attribute of rich:tree) still NOT WORKING.

                                 

                                But this can be solved with rich:treeSelectionChangeListener.

                                <h:form id="form">
                                     <rich:tree id="tree" value="#{testTree.testListRoot}" var="node"   toggleType="client" selectionType="ajax" >
                                              <rich:treeSelectionChangeListener listener="#{testTree.selectionChanged}"/>
                                     </rich:tree>
                                </h:form>
                                

                                 

                                selectionChangeListener attribute (not treeSelectionChangeListener) of rich:tree ALSO WORKS FINE, though NetBeans says that is not defined.

                                <h:form id="form">
                                     <rich:tree id="tree" value="#{testTree.testListRoot}" var="node"   toggleType="client" selectionType="ajax" selectionChangeListener="#{testTree.selectionChanged}" />
                                </h:form>
                                
                                • 13. Re: RF 4: rich:tree selectionChangeListener not invoked
                                  nbelaevski

                                  Valeriy,

                                   

                                  You should define rowKeyConverter in the case of Integer key used in TreeNode. Are you using 4.0.0.Final or CR1 BTW?

                                  • 14. Re: RF 4: rich:tree selectionChangeListener not invoked
                                    fpr69

                                    Thank you very much Valeriy !!!!  This resolved my issue.

                                     

                                    My issue was that NetBeans was giving me an error on the use of selectionChangeListener so I was using the treeSelectionChangeListener attribute, which doesn't work.  I also tried the rich:treeSelectionChangeListener listener="#{bean.listenerMethod}"/> and this also worked.

                                     

                                    I'm back in business, thank you Valeriy.

                                    1 2 Previous Next