users@javaserverfaces.java.net

Prevent mixing of Ajax and full request

From: Thomas Asel <thomas.asel_at_gmail.com>
Date: Thu, 5 Aug 2010 13:19:33 +0200

Hi Everybody,

i was thinking about how to prevent the user from mixing asynchronous and
full postback requests.
For example if there is <h:inputText> that triggers some validation with the
DOM change event and a navigation button that submits via POST. If the user
enters some text in the input field an clicks the button bevor leaving the
input, both requests are submitted on the same user action. This typically
causes a alert box telling about the mixed requests.

I wrote a little javascript for this, the function waitForAjaxToComplete is
triggered by the onclick attribute of <h:commandButton>. Its purpose is to
submit the <h:commandButton> via Ajax if there are other Ajax requests
pending.
Unfortunately it seems like the page is just rested when the function is
executed completely. No transition to an other page is performed as it would
be the case when the button is submitted via POST.

ajaxStatus = "complete";

jsf.ajax.addOnEvent(setAjaxStatus);

function setAjaxStatus(data){
    ajaxStatus = data.status;
}

function waitForAjaxToComplete(source, event){

    if(ajaxStatus === "begin"){
       jsf.ajax.request(source, event, {execute:source, render:'_at_all'});
   }
    return true;
}

Does anybody have an idea about this? Is there a better solution for the
problem?

Thank you in advance,

Thomas