4 Replies Latest reply on Jul 25, 2007 7:02 PM by sergeysmirnov

    Basic "oncomplete" question

    ksteele6

      This works just fine. It displays both alerts.

       <h:outputText value="#{MyBacking.title}" id="title">
       <h:commandButton value="Run" action="#{MyBacking.run}">
      
       <a4j:support
       event="onmousedown"
       reRender="title"
       onsubmit="alert('onsubmit');"
       oncomplete="alert('oncomplete');"/>
      
       </h:commandButton>
      


      However I really need to use the "onclick" event and not "onmousedown" for obvious reasons. When I change the event, then only the first alert displays. The one associated with "oncomplete" never displays.

       <h:outputText value="#{MyBacking.title}" id="title">
       <h:commandButton value="Run" action="#{MyBacking.run}">
      
       <a4j:support
       event="onclick"
       reRender="title"
       onsubmit="alert('onsubmit');"
       oncomplete="alert('oncomplete');"/>
      
       </h:commandButton>
      


      Please tell me there is something very simple that I'm missing (and what it is too). Thank you.

        • 1. Re: Basic

          The second produces the duplicate request. One request is by a4j:support, the second on is by h:commandButton.
          The second request is a non-Ajax one. So, the whole page is reloaded discarding the result of ajax request.

          To avoid this nightmare, you can use a4j:commandButton as a natural substitute for "h:commandButton - a4j:support" combination.
          If using the h:commandButton is extrimly important for you, add disableDefault='true' to a4j:support.

          What the Ajax4jsf version do you use, BTW?

          • 2. Re: Basic
            ksteele6

            Sergey - Thanks for the quick reply and for the help! This forum is very helpful. I've reworked the code. Here's the working version.

             <h:outputText value="#{MyBacking.title}" id="title">
             <a4j:commandButton
             value="Run"
             action="#{MyBacking.doRun}"
             reRender="title"
             onclick="alert('onclick');"
             oncomplete="alert('oncomplete');">
             </a4j:commandButton>
            


            • 3. Re: Basic
              ksteele6

              Sergey - BTW I'm using Ajax4jsf v1.1.0.

              • 4. Re: Basic

                 

                "ksteele6" wrote:
                Sergey - BTW I'm using Ajax4jsf v1.1.0.

                Yep. Since 1.1.1, the disableDefault="true" by default.