8 Replies Latest reply on Mar 25, 2012 1:59 PM by Hung Phan

    <rich:treeNode> ignoring <f:ajax> or <a4j:ajax>

    Wesley Menezes Newbie

      Hi,

       

      I have a rich:tree and I'm trying to use <f:ajax> or <a4j:ajax> in the <rich:treeNode> to capture event "click" (or any other) and thus call a bean method through the listener attribute of the ajax tag, bug the ajax tag is simply ignored.

       

      Anyone have this scenario?

       

      This is a a piece of code, not complex...

       

       

       

                                  <rich:tree
                                       id="memoriaTree"
                                       value="#{customerBean.rootNodes}"
                                       toggleType="client"
                                       var="node"
                                       nodeType="#{node.data.type}"
                                        >
                                      
                                          <rich:treeNode
                                              id="memoriaRoot"
                                              type="customer"
                                              iconLeaf="../images/fichario.gif"
                                              data="#{node.data.id}">

       

                                              <h:outputText value="#{node.data.label}" />
                                             
                                              <f:ajax
                                               immediate="true"
                                               execute="@this"
                                               event="mousedown"
                                               listener="#{customerBean.processTreeSelectionChange(node.data)}"/>
                                          </rich:treeNode>
         
                                   </rich:tree>

       

      I'm using RichFaces 4.2 and JSF 2.2 with CDI (my customerBean is of type "javax.inject.Named")

       

      Tks

       

        • 1. Re: <rich:treeNode> ignoring <f:ajax> or <a4j:ajax>
          iabughosh Master

          Welcome to the community Wesley,

          i think the problem is in your listener method signature, ajax listener signature should be like this:

           

          public void processTreeSelectionChange(AjaxBehaviorEvent abe) {

               //do your action here

          }

           

          regards.

          • 2. Re: <rich:treeNode> ignoring <f:ajax> or <a4j:ajax>
            Wesley Menezes Newbie

            Ibrahim,

             

            thanks for your answer. I tried your suggestion, but no sucess.

             

            Then I tried changing the <f:ajax> for <a4j:ajax> and again no sucess. But with <a4j:ajax> the tree blocked the tree expanding (actually, when I click to expand, the tree expand and contract very fast! What a strange behavior...).

             

            I look in RichFaces showcase something similar to your suggestion, but with <rich:extendedDataTable>.

             

            So, my impression is that maybe a problem with "treenode"...

             

            I checked app server log and httpfox messages, but no clues. By the way, in httpfox, I see that when "mousedown" occurs it creates a post request whit result 200 (ok!), but no method call on server!

             

            Tks again!

            • 3. Re: <rich:treeNode> ignoring <f:ajax> or <a4j:ajax>
              Maheswara Sunkara Novice

              are you still using : listener="#{customerBean.processTreeSelectionChange(node.data)}"

               

              or changed it to : listener="#{customerBean.processTreeSelectionChange}"

              • 4. Re: <rich:treeNode> ignoring <f:ajax> or <a4j:ajax>
                Wesley Menezes Newbie

                Hi Maheswara,

                 

                Actually I need to use the new form, passing arguments:

                listener="#{customerBean.processTreeSelectionChange(node.data)}"

                 

                But trying to understand what was the problem I tried method with no arguments.

                 

                Both ways the result was the same, no sucess, no method call for <rich:treeNode>.

                 

                Thank you

                • 5. Re: <rich:treeNode> ignoring <f:ajax> or <a4j:ajax>
                  Hung Phan Newbie

                  Hello Mendes.

                   

                  I have the same problem with you too.

                   

                  I understand why you create that method. I think because the treeSelectionChangeEvent in rich:tree not show exactly as this demo, so you have to give data directly when click rich:treeNode.

                   

                  I've tried this code in this demo (http://showcase.richfaces.org/richfaces/component-sample.jsf?demo=tree&skin=blueSky), but the treeSelectionChangeListener doesn't active, so desperate.

                   

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

                   

                    <rich:tree id="tree" nodeType="#{node.type}" var="node" value="#{treeBean.rootNodes}" toggleType="client"

                                  selectionType="ajax" selectionChangeListener="#{treeBean.selectionChanged}">

                                  <rich:treeNode type="country">

                                      #{node.name}

                                  </rich:treeNode>

                                  <rich:treeNode type="company" icon="/images/tree/disc.gif">

                                      #{node.name}

                                  </rich:treeNode>

                                  <rich:treeNode type="cd" icon="/images/tree/song.gif">

                                      #{node.artist} - #{node.name} - #{node.year}

                                  </rich:treeNode>

                   

                  If you have free time, please check my test case project in my wordpress: http://phandanghung.wordpress.com/2012/03/22/welcome-to-my-jsf-tutorial-project/. Please check test case 3 to view our problem

                   

                  Sincerely thanks.

                  • 6. Re: <rich:treeNode> ignoring <f:ajax> or <a4j:ajax>
                    Wesley Menezes Newbie

                    Hello Hung,

                     

                    I will test your sample, just give me some time, but I will test...

                     

                    Mean time, to my problem, I could do something right now that will gave same efffect (events on treeNode), but the solution is not so elegant, look:

                     

                    First in XHTML:

                    <rich:treeNode ... onmousedown="processTreeSelectionChange(#{node.data.id})"/>

                     

                     

                    Second still XHTML:

                     


                    <a4j:jsFunction name="processTreeSelectionChange" action="#{memoriaLaudoTreeCreatorBean.processTreeSelectionChange}">

                      <a4j:param name="node" assignTo="#{memoriaLaudoTreeCreatorBean.elementoSelecionadoId}"/>

                    </a4j:jsFunction>

                     

                     

                    Third CDI Bean:

                    ...

                    private String elementoSelecionadoId;

                    ...

                    //getter and setter

                    ...

                    public void processTreeSelectionChange ( )  {

                      //recover original node from the elementoSelecionadoId (searching in rootNodes)

                    }

                     

                     

                    Well, this will help me for a while, but I would like to use the new form of calling methods with arguments, present in JSF 2.2.

                     

                    Still, I opened a bug report in RichFaces 4.2.0 Final Jira, if I have some answer from there I will post here that answer.

                     

                    Best Regards

                    Wesley Menezes

                    • 7. Re: <rich:treeNode> ignoring <f:ajax> or <a4j:ajax>
                      Hung Phan Newbie

                      Thank you Wesley Meneles.

                       

                      I've tried to code like you, but unfortunately, the treeSelectionChange event doesn;t work. My code like this

                       

                       

                       

                      Header 1

                      <rich:tree id="tree"  nodeType="#{node.type}" var="ajax" value="#{testCase4Bean.rootNodes}" toggleType="client"

                      selectionType="ajax">

                      <rich:treeNode type="country" onclick="processTreeSelectionChange(#{node.name})">

                      #{node.name}

                      </rich:treeNode>

                      </rich:tree>

                       

                      And js like this

                       

                      <a4j:jsFunction name="processTreeSelectionChange" action="#{testCase4Bean.processTreeSelectionChange()}">

                      <a4j:param name="node" assignTo="#{testCase4Bean.myNodeData}"/>

                      </a4j:jsFunction>

                       

                      likes many times. I feel so bad .

                      • 8. Re: <rich:treeNode> ignoring <f:ajax> or <a4j:ajax>
                        Hung Phan Newbie

                        Finally I've done this function successfully . I have to change like this:

                         

                        Header 1

                        <rich:tree id="tree"   nodeType="#{node.type}" var="node" value="#{testCase4Bean.rootNodes}" toggleType="client"

                        selectionType="ajax" >               

                        <rich:treeNode type="country">

                        <a4j:ajax event="click" oncomplete="processTreeSelectionChange('#{node.name}')"/>

                                             #{node.name}

                        </rich:treeNode>

                        </rich:tree>

                        ....

                         

                          <a4j:jsFunction name="processTreeSelectionChange" render="showname">

                        <a4j:param name="name" assignTo="#{testCase4Bean.myNodeData}" />

                        </a4j:jsFunction>

                         

                        And it success. I think this is a bug that developers can change in the 4.3.0 release