3 Replies Latest reply on May 4, 2007 8:32 AM by ilya_shaikovsky

    a4j:form and onsubmit event.

    fran.fuentes

      Ok, this maybe a result of my ignorance (hope that not).

      Having declared an a4j:form and a short piece of code in the onsubmit event

      alert("hello")
      of the form, I've found that if the user push a button (h:commandButton inside the form), this event is fired twice, but if the action of submit is done by a commandLink, event is fire only once.

      Is this an usual and known behavior?

      Thanks you very much.

        • 1. Re: a4j:form and onsubmit event.
          ilya_shaikovsky

          Ok. Let I explain you what happens.

          I? you put the ajax-ed control to simple h:form - there is no submit appears. It just emulated by framework. So we must emulate onsubmit also. But if you used ajax-ed form and ajax-ed link - just form submit calls and there is two instances of onsubmit called - browser onsubmit and emulated one.

          I thnk you can create some minor bug to make a4j checks if the onsubmit was fired by browser before call it itself.

          And my main question to you is - did you really need ajax-ed form?

          • 2. Re: a4j:form and onsubmit event.
            fran.fuentes

             

            "ilya_shaikovsky" wrote:

            I? you put the ajax-ed control to simple h:form - there is no submit appears. It just emulated by framework. So we must emulate onsubmit also. But if you used ajax-ed form and ajax-ed link - just form submit calls and there is two instances of onsubmit called - browser onsubmit and emulated one.


            So this is what happens (based in my case and what you said about the emulation):
            -The form is an ajax-ed form.
            -If I push a non-ajax-ed button (h:commandButton), the onsubmit event of the form is fired twice (because the emulated onsubmit AND the real onsubmit of the form).
            -If I push an ajax-ed link (a4j:commandLink), the onsubmit event of the form is fired once (because the control is in hands of the framework since the start of the call).

            That's right?

            Well, maybe I'll create this bug (must find where :-))

            Why do I need a full ajax-ed form? I don't know. I just evaluating the use of this framework inside our project. First I'm reading all the tags, trying to look the way they work, alone and together, sticking every corner. After that, I'll write an intern recommendation of use.

            Now, my first conclusion is that this framework has a lot of ways of doing the same: to send a form using AJAX and processing results. I need to find the most reasonable and non intrusive way of adding AJAX to our project and maybe some support and region and not a full form will be the only things we need.

            By the way, I've found some other problems with the interactions of tags. May I suppose this is the right place of talking about them after deciding if something is a bug or not?

            Again, thank you for your reading and reponse.




            • 3. Re: a4j:form and onsubmit event.
              ilya_shaikovsky

              So all you need is to understand that ajax-ed forms - is designed for exceptional cases (to ajaxify some JSF/MyFaces complex component). Read about it in the documentation.

              All you need is to use ajax action components in simple form instead of JSF ones to send an ajax request instead of common server submit. And on these controls choose the areas or the components to be updated.

              Please look at our developer Guide to investigate base principles and run our examples to kick start in ajax4jsf.

              Good Luck.. :) Ask more if need.