You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@myfaces.apache.org by Mark Li <xi...@gmail.com> on 2010/03/25 07:38:50 UTC

Is there any 'oncomplete' method in jsf.ajax.request()?

I cant find oncomplete like method in jsf.ajax.request specification(314), or in the js source code ?
Can myfaces 2 support this method?


Best Regard

Mark Li
xihanlee@gmail.com





Re: Is there any 'oncomplete' method in jsf.ajax.request()?

Posted by Werner Punz <we...@gmail.com>.
Hello, there is no onComplete in the specification, because you won´t 
need it, the specification defines an event system where you can 
register your own listeners, with then you can check whether a request 
is complete or not.

You can use the jsf.ajax.addOnEvent method to register your own 
listener. (respectively jsf.ajax.addOnError for error listeners)


Alternatively you can pass the listener in the request parameters (if 
you just need it for a single request)

<commandButton id="button1" value="submit"
     onclick="jsf.ajax.request(this,event,
       {execute:'button1',render:'status',onevent: handleEvent,onerror: 
handleError});return false;"/>
</commandButton/>


The event listener function gets passed an object and that one has the 
attribute status, which shows the status of the current request.
The status shows the status of the currently running request you can use
that one for your onComplete.

Here is a small example for an onEvent listener

var processEvent = function processEvent(data) {
   if (data.status == "begin") {
     alert('Begin');
   } else if (data.status == "complete") {
     alert('Complete');
   } else if (data.status == "success") {
     alert('Success');
   }
}


jsf.ajax.addOnEvent(processEvent);

So as you can see an onComplete is not really needed although the api is 
a little bit more low level (which is ok for a spec) it achieves the same.

Have in mind the current spec does not allow the deregistration of 
listeners, so either use the local ones, or just use one global one for 
the effect you want to achieve.


Cheers

Werner




Am 25.03.10 07:38, schrieb Mark Li:
> I cant find oncomplete like method in jsf.ajax.request specification(314), or in the js source code ?
> Can myfaces 2 support this method?
>
>
> Best Regard
>
> Mark Li
> xihanlee@gmail.com
>
>
>
>
>