10 Replies Latest reply on May 26, 2011 11:25 AM by ginc

    oncomplete does not get fired after actionListener finished processing

    ginc

      Hi everyone,

       

      recently I upgraded to richfaces 4 and jsf 2 in order to solve the IE9 issue. The page is rendered fine, the problem is, that it does not function correctly anymore.

       

      I am using commandButton and jsFunction to access actionListener method, after that the oncomplete should fire another js function. But it doesn't!

       

       

      <a4j:jsFunction name="syncInput"
                          oncomplete="alert('hello')"
                          actionListener="#{Bean.syncInput}"
                          render="user_input"/>
      
      <a4j:commandButton value="test" actionListener="#{ChatBean.syncInput}" oncomplete="alert('hello')" />
      

       

      The alerts never occur with oncomplete, but they do with the other events like onclick.

       

      Is this a bug, or am I mistaken her?

       

      Gregor

        • 1. Re: oncomplete does not get fired after actionListener finished processing
          ppitonak

          Hi Gregor,

           

          I've tried both jsFunction and commandButton and oncomplete works fine in Chrome and IE9. Could you please provide more information about your environment?

           

          Regards,

          Palo

          • 2. Re: oncomplete does not get fired after actionListener finished processing
            ginc

            I have tried it now in Firefox 3.6.17, IE9 - neither of them work.

             

            I am using richfaces 4.0.0.Final and jsf 2.1.1

             

            When executing the following code, the alert of oncomplete does not occur. ActionListener works fine.

             

            This:

             

            <!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">

             

            <h:head>

                <title>test</title>

            </h:head>

             

            <h:body>

                <f:view>

                    <h:form id="main_form" acceptCharset="UTF-8">

                        <a4j:commandButton value="test" actionListener="#{ChatBean.syncInput}" oncomplete="alert('hello')" />

                    </h:form>

                </f:view>

            </h:body>

            </html>

             

            Produce the following html code:

             

            <!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">

            <head>

                <title>test</title>

                <link type="text/css" rel="stylesheet" href="/rfRes/skinning.ecss.jsf?db=eAHL6rC8BQAEkAIG"/>

                <script type="text/javascript" src="/javax.faces.resource/jsf.js.jsf?ln=javax.faces&amp;stage=Development"></script>

                <script type="text/javascript" src="/javax.faces.resource/jquery.js.jsf"></script>

                <script type="text/javascript" src="/javax.faces.resource/richfaces.js.jsf"></script>

                <script type="text/javascript" src="/javax.faces.resource/richfaces-queue.js.jsf"></script>

            </head>

            <body>

            <form id="main_form" name="main_form" method="post" action="/test2.jsf" enctype="application/x-www-form-urlencoded">

                <input type="hidden" name="main_form" value="main_form"/>

                <input id="main_form:j_idt6" name="main_form:j_idt6"

                       onclick="RichFaces.ajax(&quot;main_form:j_idt6&quot;,event,{&quot;incId&quot;:&quot;1&quot;} );return false;"

                       value="test" type="submit"/><input type="hidden" name="javax.faces.ViewState" id="javax.faces.ViewState"

                                                          value="-608878335606438827:-3715234858006091902" autocomplete="off"/>

            </form>

            </body>

            </html>

             

            The funny thing is, oncomplete is NOT there! if I change it to any other event, like onclick or onmousedown, it is there and therefore works fine.

             

            Looks like a bug to me, still..

             

            Any thoughts about that?

            • 3. Re: oncomplete does not get fired after actionListener finished processing
              snaker

              try this:

               

              <h:form>

                   <a4j:outputPanel ajaxRendered="true">

                        <a4j:commandLink.....>

                   </a4j:outputPanel>

              </h:form>

              • 4. Re: oncomplete does not get fired after actionListener finished processing
                ginc

                This also does not work. Neither with commandLink nor with commandButton.

                 

                @Kike I am wondering why this would solve the problem anyway. The problem is not that it is there but does not get called. It ist not there at all and therefore does not get called. So the question is - why is the oncomplete not rendered.

                • 5. Re: oncomplete does not get fired after actionListener finished processing
                  ppitonak

                  Hi Gregor,

                   

                  I tried your sample in Glassfish 3.1, JBoss 6.0.0.Final and Tomcat 6.0.32 with Mojarra 2.0.4 and 2.1.1-b04 and I still cannot reproduce the bug. I see alert each time.

                   

                  Regarding the rendered markup...it's usual that oncomplete is not rendered on the page. Actually it cannot be rendered because it is not a HTML attribute (unlike onclick). Otherwise the markup wouldn't be valid. When I watch Ajax request, I see the following response for your sample:

                   

                  <?xml version='1.0' encoding='UTF-8'?>

                  <partial-response><changes><update id="javax.faces.ViewState"><![CDATA[1548791213828025428:-1613907399947497364]]></update><extension id="org.richfaces.extension"><complete>alert('hello');</complete></extension></changes></partial-response>

                   

                  As you can see, there is alert('hello') in "complete" part of the response.

                   

                  Regards,

                  Palo

                  • 6. Re: oncomplete does not get fired after actionListener finished processing
                    ginc

                    Hi Palo,

                     

                    I certainly do understand that oncomplete is not rendered like the others, since it is not a html standard element. I probably articulate myself not clear enough.

                     

                    Anyway, since it seems just to be an issue at my side, how can I figure out what the problem is? I mean it is a very simple example, so i don't know what to change anymore in order to make it work.

                     

                    Any suggestions?

                     

                    Gregor

                    • 7. Re: oncomplete does not get fired after actionListener finished processing
                      ppitonak

                      Could you prepare a simple project? I would try it.

                      • 8. Re: oncomplete does not get fired after actionListener finished processing
                        snaker

                        because render all elements inside outputpanel when you pulse the button and it would render oncomplete and show the alert

                         

                        • 9. Re: oncomplete does not get fired after actionListener finished processing
                          snaker

                          one question

                           

                          you have this:

                           

                          <a4j:jsFunction name="syncInput"......>

                          and

                          <a4j:commandButton actionListener="#{ChatBean.syncInput}"......>

                           

                          What momment are you calling jsFunction??? you try call jsFunction with actionListener="#{ChatBean.syncInput}"???

                          • 10. Re: oncomplete does not get fired after actionListener finished processing
                            ginc

                            I have found the piece of code which was responsible for this issue.

                             

                            Back in the days, when using jsf 1.2, I was using a phase listener from balusC (http://balusc.blogspot.com/2007/03/post-redirect-get-pattern.html), for redirect purposes. It seemed to work fine with the new version too.. Well, it does not. Using this phaselistener prevents the oncomplete attribute from beeing executed. So I removed it. Now it works fine.

                             

                            @Palo thanks for making me prepare a simple project.. :-)

                             

                            @Kike thanks for your inputs, for sake of completeness - i was not about to call jsFunction with the actionListener. I just needed to ways to access the actionListener. one from a button, one from an key event ('enter' within a inputbox)

                             

                            Problem solved..  Now back to work.

                             

                            Gregor