7 Replies Latest reply on Nov 10, 2008 9:29 PM by nbelaevski

    eventqueue and confirm box in onsubmit()

    ronanker

      Hi all,

      We are using RF 3.2.1RC3 with JSF1.2

      We encounter an issue using eventQueue and onSubmit on a form.

      All our ajax request are sent using a eventQueue.

      We are using "onSubmit" to display a confirm box to the user.
      But if the user abort the form submit (click to 'no' in the confirm box), the request is not send (nice) but all the other following ajax requests the user will make won't be send too.

      In the debug console, we only can see

      debug[19:00:26,637]: Put new event to queue RequestQueue


      It seems that the aborted request is not removed from the queue and thus, all the following requests are added to it without any chance to be executed.

      I've not found anything on this in the RF Jira, I would like to know if there is a known workaround.

      Thanks for any help.


        • 1. Re: eventqueue and confirm box in onsubmit()
          nbelaevski

          Hello,

          Yes, I've already seen the problem on 3.2.2. You're right - the problem is caused by request not being cleared. We're redesigning queues feature right now so the problem will be fixed in 3.3.0. There's no known workaround; looks like the only way to fix that is to patch JSFAJAX.js script: http://fisheye.jboss.org/browse/RichFaces/trunk/framework/impl/src/main/javascript/ajaxjsf/JSFAJAX.js?r=10604 - the bug is in A4J.AJAX.Submit method. Or you can override it by:

          A4J.AJAX.Submit = function(){ ... }
          in your code

          • 2. Re: eventqueue and confirm box in onsubmit()
            ronanker

            Thanks for your reply!

            Well the A4J.AJAX.Submit() method is quit big. I'm not sure i want to override it.

            I made a fix directly in our onSubmit() method :

            ...
            if (!confirm(message)){
            
             //Hacking RichFaces : queues should be cleared if onsubmit return false
             var eventsQueue = A4J.AJAX._eventsQueues['requestQueue'];
            
             if( eventsQueue ) {
             A4J.AJAX._eventsQueues['requestQueue']=false;
             if(eventsQueue.wait){
             LOG.debug("Queue not empty, execute next request in queue "+options.eventsQueue);
             A4J.AJAX.SubmiteventsQueue(eventsQueue);
             }
             }
             //end hacking
             return false;
            }
            ...
            


            Does it look good for you ?


            • 3. Re: eventqueue and confirm box in onsubmit()
              nbelaevski

              Can you please post complete code?

              • 4. Re: eventqueue and confirm box in onsubmit()
                ronanker

                Here it is,

                In our JSPs:

                <a4j:form id="form" onsubmit="return validateForm(this);">
                ...
                
                 <a4j:commandLink action="#{bean.onClickSave}"
                 onclick="linkType=L_SAVE;"
                 reRender="form"
                 eventsQueue="requestQueue">
                 <h:graphicImage title="#{Labels.SAVE}" url="#{Images['Save.png']}" />
                 </a4j:commandLink>
                ...
                </a4j:form>
                


                in our js file
                function validateForm(f) {
                 // ... some code to retrieve the message...
                
                 if (!confirm(message)){
                
                 //Hacking RichFaces : queues should be cleared if onsubmit return false
                 var eventsQueue = A4J.AJAX._eventsQueues['requestQueue'];
                
                 if( eventsQueue ) {
                 A4J.AJAX._eventsQueues['requestQueue']=false;
                 if(eventsQueue.wait){
                 LOG.debug("Queue not empty, execute next request in queue "+options.eventsQueue);
                 A4J.AJAX.SubmiteventsQueue(eventsQueue);
                 }
                 }
                 //end hacking
                 return false;
                 }
                }
                


                Notice that we always use the same queue 'requestQueue'.

                It seems correct to you ?



                • 5. Re: eventqueue and confirm box in onsubmit()
                  nbelaevski

                  It seems to me there's no need to send request from queue if confirm call returns false even if eventsQueue.wait is true. Why not just clear the queue?

                  • 6. Re: eventqueue and confirm box in onsubmit()
                    ronanker

                    I don't know !
                    We just did the same as in the A4J.AJAX.finishRequest() method.

                    If you think that

                    ...
                     if( eventsQueue ) {
                     A4J.AJAX._eventsQueues['requestQueue']=false;
                     }
                    ...
                    

                    is enough. It's fine for us.
                    In fact, I tought if there is some request pending in queue, we should send it via
                    A4J.AJAX.SubmiteventsQueue(eventsQueue);
                    



                    • 7. Re: eventqueue and confirm box in onsubmit()
                      nbelaevski

                       

                      "RonanKER" wrote:
                      If you think that
                      ...
                       if( eventsQueue ) {
                       A4J.AJAX._eventsQueues['requestQueue']=false;
                       }
                      ...
                      

                      is enough. It's fine for us.