4 Replies Latest reply on Jun 24, 2009 6:56 PM by Tim Evers

    <a4j:support ..../> question

    Tim Evers Master

      I have a weird problem I'm hoping someone can point out what silly mistake I'm making.

      In this scenario:

      <a4j:log />
      <a4j:region id="testArea">
       <h:inputText value="">
       <a4j:support
       event="onchange"
       reRender="testArea" />
       </h:inputText>
      </a4j:region>
      <h:commandButton
       action="#"
       value="Blah"
       onclick="alert('button clicked')" />
      

      Everything works as I expect. My example is this. Enter some text in the text inputText component and then without tabbing out of the inputText component use the mouse to click the commandButton.
      I expect:
      1. Ajax event to fire (I see this happen in the log) (yes)
      2. Alert "button clicked" to be displayed (yes)

      But if I change my example to this :
      <a4j:log />
      <a4j:region id="testArea">
       <h:inputText value="">
       <a4j:support
       event="onchange"
       reRender="testArea"
       onsubmit="alert('start ajax');" />
       </h:inputText>
      </a4j:region>
      <h:commandButton
       action="#"
       value="Blah"
       onclick="alert('button clicked')" />
      

      Yep, all I've done here is added an onsubmit event to the a4j:support tag. My expectations are this:
      1. Alert saying "start ajax" (yes)
      2. Ajax event fires (yes)
      3. Alert "button clicked" (no) - Why does this fail?

      So does anyone know why if I put any javascript in the onsubmit OR oncomplete attributes, then events that should happen after the ajax call dissapear.

        • 1. Re: <a4j:support ..../> question
          Nick Belaevski Master

          Hi Kragoth,

          Are you observing the wrong behavior if you do not use alert() for onsubmit, but something another, e.g.

          window.status = 'start';
          ?

          • 2. Re: <a4j:support ..../> question
            Tim Evers Master

            Hi nbelaevski,

            The suggestion you made is something I tried late yesterday and yes when I do that it works. (Obviously I need to do some more reading because I do not understand why an alert changes the behaviour but that's another question. :)

            When I do a non alert javascript call it appears to behave correctly. Athough I'm having trouble with what I'm trying to do but I'm almost there :)


            If you do know why the alert doesn't work I would appreciate an explanation, otherwise I'll go google around and do some reading.

            Thanks again.
            Tim

            • 3. Re: <a4j:support ..../> question
              Nick Belaevski Master

              Hi Tim,

              I think it's browser dependent behavior; user events in chains are lost if modal window such as alert appears for some of them.

              • 4. Re: <a4j:support ..../> question
                Tim Evers Master

                Thanks.

                I've now finally managed to get my problem sorted.
                But I did notice some weird behaviour.

                Using the following example (I think its right, I've had to cut it down a lot from my project)

                <h:form onsubmit="showPleaseWaitModalPanel();">
                 <h:inputText id="input">
                 <h:outputText id="output"/>
                 <a4j:support event="onchange" onsubmit="showPleaseWaitModalPanel();" oncomplete="hidePleaseWaitPanel();" reRender="output"/>
                 </h:inputText>
                 <h:commandLink value="save" action="#{Bean.save()}" />
                </h:form>
                


                If I have my cursor in the inputText and change the value then using my mouse click the commandLink it appears that the action never happens.
                However, If I remove the onsubmit from the form then it works.
                So all I did is change the form from having onsubmit="....." to adding an EventListener to the form and that seems to work fine.

                I don't really think there is a bug anywhere here but obviously something I'm doing is getting in the way.

                But I'm happy enough, I've got things working and probably better overall design anyway.


                Thanks for the help.