Ajax integration with JSF 2.0

Source: Internet
Author: User
Ajax integration with JSF 2.0

In JSF 2.0, an Ajax engine will be implemented on the client side. It will be responsible for the following:
1. Sending an Ajax request to the server.
2. Processing the partial response then updating or inserting new element (s) in the client Dom.

At the client,The Ajax engine (which will be represented
In the (Ajax. JS) file) will construct the Ajax request which will
Contain the following:
1. the name and value of the source element that triggers the Ajax request.
2. A single parameter that says that this request is an Ajax
Request. This parameter is called (javax. Faces. Ajax. Partial) and its
Value is set to true.
3. The encoded view State.
4. The set of client IDs that must be processed in the partial view
Execute phases, and the set of client IDs that must be processed in
Partial View render phase.

At the server,The request will be recognized whether it
Is an Ajax request or not by checking the (javax. Faces. Ajax. Partial)
Request Parameter. If it is an Ajax request, a partial view execute and
A partial view render will be applied on the components sent in
Ajax request (check the previous step 4). Finally the server will
Generate the content data in a language understandable by the client
(May be XML or JSON ).

At the client,The Ajax Client Engine will receive
Server Response, and wocould interpret it to know whether to update or
Insert new elements to the Dom.

Notes:
1. The facescontext. isajaxrequest () method can be used to check whether the current request is an Ajax request or not.
2. All of the Ajax engine requests shoshould be asynchronous, and
Ensure their correct execution order, the request will be enqueued
(Once the component initiate it) and dequeued (once the request
Completed execution) from a request queue.

A simple example to define strate the idea (from the JSF 2.0 specs ED2 ):

<H: commandbutton id = "Submit" value = "Submit"
Onclick = "javax. Faces. Ajax. ajaxrequest (this, event,

From: http://www.jroller.com/HazemBlog/entry/ajax_integration_with_jsf_2
{Execute: 'submit ', render: 'outtext'}); Return false; "/>

This will execute the partial view execute on the 'submit 'button
And the partial view render on the 'outtext' component at the end.

Finally, I wowould like to mention that the script resources in JSF 2.0
Are relocatable meaning that you can control their encoding place
Setting the target attribute of the resource component.
@ Resourcedependency annotation can be also used before the component
Renderer class to achieve the same functionality.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.