Ajax Integration with JSF 2.0

來源:互聯網
上載者: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. Receiving 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 the
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 the
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 the
server response, and would 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 should be asynchronous, and to
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 illustrate the idea (From the JSF 2.0 specs ED2):

<h:commandbutton id="submit" value="submit"
onclick="javax.faces.ajax.ajaxRequest(this, event,

轉自: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 would like to mention that the script resources in JSF 2.0
are relocatable meaning that you can control their encoding place by
setting the target attribute of the resource component. The
@ResourceDependency annotation can be also used before the component
renderer class to achieve the same functionality.

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.