6 Replies Latest reply on Mar 16, 2007 1:48 PM by andrew.rw.robinson

    a4j:form oncomplete not implemented?

    andrew.rw.robinson

      I was attempting to execute code after all the in-line tags had been executed. The status onstop was getting executed before the scripts, so I tried using the oncomplete attribute of a4j:form. Interestingly enough, this code is never evaluated and I can't find anywhere in the source code that uses the form's oncomplete (the command link and command button components are just fine).

      Is this feature not yet supported for the form?

      <a4j:form
      id="zfpForm"
      onsubmit="alert('this is OK');"
      oncomplete="alert('You will never see this');">


        • 1. Re: a4j:form oncomplete not implemented?

          It should. If not, it is a bug

          • 2. Re: a4j:form oncomplete not implemented?
            alexsmirnov

            <a4j:form > component without 'ajaxSubmit' attribute set to 'true' submitted by post method, not a with XmlHttpRequest.

            • 3. Re: a4j:form oncomplete not implemented?
              andrew.rw.robinson

              what about:

              <a4j:form oncomplete="alert('okay');">
              <a4j:commandLink value="ajax me" />
              </a4j:form>

              In this simple example I am not getting the "okay" alert, and this is definitely submit by AJAX and not an HTTP POST.

              Here is an example that should work IMO, but doesn't:

              <!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:a4j="https://ajax4jsf.dev.java.net/ajax"
               xmlns:h="http://java.sun.com/jsf/html"
               xmlns:f="http://java.sun.com/jsf/core">
              
               <body>
               <a4j:form oncomplete="alert('AJAX is done');">
               <a4j:commandLink value="submit AJAX" />
               <a4j:status startText="AJAX in progress"
               stopText="" />
               </a4j:form>
               </body>
              </html>


              This is the work-around I have found:
              <!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:a4j="https://ajax4jsf.dev.java.net/ajax"
               xmlns:h="http://java.sun.com/jsf/html"
               xmlns:f="http://java.sun.com/jsf/core">
              
               <body>
               <a4j:form>
               <a4j:commandLink value="submit AJAX" />
               <a4j:status startText="AJAX in progress"
               stopText="" />
               <script language="javascript" type="text/javascript">
              // <![CDATA[
              A4J.AJAX.AddListener({
               onafterajax: function(req,domEvt,data) {
               window.setTimeout('alert("on complete");', 50)
               }
              });
              // ]]>
               </script>
               </body>
              </html>


              • 4. Re: a4j:form oncomplete not implemented?

                Ok. I see now, what Alex means.

                andrew, a4j:form might work in Ajax or non-Ajax mode. It contains several attributes that belongs to Ajax Command Components API. However, if a4j:form works in non-Ajax mode, those attribute just do not make any sense

                To turn a4j:form in ajax mode, you need to set the ajaxSubmit attribute to true (it is false by default)

                If a4j:form works in Ajax mode, all the non-ajax command components (h:commandButton, h:commandLink and so on) become ajaxified (this is slight the same approach that AjaxAnywhere has)

                Conclusion - oncomplete should not work without ajaxSubmit="true"

                • 5. Re: a4j:form oncomplete not implemented?
                  alexsmirnov

                  Right code will be :

                  <a4j:form oncomplete="alert('okay');" ajaxSubmit="true">
                  <a4j:htmlCommandLink value="ajax me" />
                  </a4j:form>

                  or :
                  <a4j:form>
                  <a4j:commandLink value="ajax me" oncomplete="alert('okay');"/>
                  </a4j:form>


                  form component in ajax4jsf is designed for two use-cases:
                  1) Update <h:form> component or append <h:commandLink > by AJAX can provide some JavaScript errors ( original JSF components don't know about partial updates ). <a4j:form>/<a4j:htmlCommandLink> is safe for partial updates.
                  2) a4j:form with ajaxSubmit="true" attribute can append AJAX functionality to third-party components, like MyFaces extended data table, data scroller, tab panel etc.

                  • 6. Re: a4j:form oncomplete not implemented?
                    andrew.rw.robinson

                    Okay, that is what I was afraid of. I was looking for a solution to have JavaScript that *always* executed after an A4J post regardless of the region that was submitted. Looks like the A4J.AddListener javascript call is what I need. Thanks.

                    FYI: does A4J work with uploading files/multi-part data? With AjaxAnywhere, uploading files had to be done through a normal HTTP POST with enctype multipart. I was not sure if that was an AjaxAnywhere limitation or an AJAX limitation.