Search |
||
JSF 2: Ajax Events and ErrorsPosted by driscoll on May 15, 2009 at 4:06 PM PDT
Today I want to look at how to handle Ajax events and errors in JSF 2.
JSF 2's Ajax support includes a very basic facility to listen for events and errors within JSF's client side processing code. It's envisioned that this will primarily be used by component developers that wish to monitor events - for instance, turning an image yellow when there's an outstanding Ajax request, and black when there isn't. So, without further ado, here's a few snips of code from Mojarra's ajax-queue demo:
In a page with some Ajax calls, we have the following field:
A simple textarea, not even hooked into the backend server data model.
Then in our javascript (for the demo, in a separately loaded file, though it could just as easily be in page) we have:
When run, you'll see a stream of data going through the textarea as ajax events happen elsewhere in the page. Try out the demo to see more. (Again, it's in the Mojarra codebase, under jsf-demo/ajax-queue)
What's happening: first we define a JavaScript function, place it in a variable, and then call two JSF ajax api functions:
That data object, along with the functions themselves, are defined in Section 14.4 of the JSF 2 specification. I'll outline a little of what's in there here, but be sure to check it out for the full scoop - it's a pretty easy to read and understand part of the spec.
For Events, there are three named events: begin, complete, and success.
This means that for a normal request, all three will be called, while if there is some sort of error, then only begin and complete will be called.
For Errors, there are four named errors possible.
The data payload consists of:
»
Comments
Comments are listed in date ascending order (oldest first)
Submitted by b_faissal on Sat, 2009-05-23 05:17.
I want to ask you if there is a reference documentation for JSF 2.0 as it's for JSF 1.2 (at SUN JEE tutorials) ?
Thanks
|
||
|
|