简体   繁体   中英

How to use Ajax with JSF 2.0?

I want to implement Ajax on my JSF web project. I googled and found that ICEFaces is supporting Ajax with JSF. Yet I dont know the usability of it.

Any one has experience Ajax/JSF, please guide me where to move.

[EDIT]

If any one has experienced on similar, please share the usability as well. the good and bad..

JSF 2.0 has built-in support for Ajax using the f:ajax tag. All three of ICEFaces, OpenFaces, and RichFaces also have Ajax-enabled components but with JSF 2.0 it is now possible to add Ajax to your apps without using third-party libraries. IBM has a series of nice tutorials in this regards: http://www.ibm.com/developerworks/views/java/libraryview.jsp?search_by=JSF+2+fu

JSF 2.0 has built in basic AJAX functionality through the f:ajax tag.

David Geary shows how in part 3 of his jsf-fu articles. http://www.ibm.com/developerworks/java/library/j-jsf2fu3/index.html

It is quite simple and elegant to use Ajax in JSF but you should not abuse because of debugging constraints.

HTML page Fragment :

 <h:commandLink  value="tab 1">
    <f:param name="tabIndex" value="1" />
    <f:ajax event="click" render=":contentForm" listener="#{tabBB.handleTabChange}"/>
 </h:commandLink>

Backing bean fragment :

public boolean handleTabChange() {
    ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
    String index = externalContext.getRequestParameterMap().get("tabIndex");
    setTabIndex(Integer.parseInt(index));
    return true;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM