简体   繁体   English

如何在JSF 2.0中使用Ajax?

[英]How to use Ajax with JSF 2.0?

I want to implement Ajax on my JSF web project. 我想在我的JSF Web项目上实现Ajax。 I googled and found that ICEFaces is supporting Ajax with JSF. 我搜索了一下,发现ICEFaces通过JSF支持Ajax。 Yet I dont know the usability of it. 但是我不知道它的可用性。

Any one has experience Ajax/JSF, please guide me where to move. 任何人都有Ajax / JSF的经验,请指导我搬到哪里。

[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. JSF 2.0使用f:ajax标记内置了对Ajax的支持。 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. ICEFaces,OpenFaces和RichFaces的所有三个都还具有支持Ajax的组件,但是使用JSF 2.0,现在可以在不使用第三方库的情况下将Ajax添加到您的应用程序中。 IBM has a series of nice tutorials in this regards: http://www.ibm.com/developerworks/views/java/libraryview.jsp?search_by=JSF+2+fu IBM在这方面有一系列不错的教程: 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. JSF 2.0通过f:ajax标记内置了基本的AJAX功能。

David Geary shows how in part 3 of his jsf-fu articles. David Geary在他的jsf-fu文章的第3部分中展示了如何进行。 http://www.ibm.com/developerworks/java/library/j-jsf2fu3/index.html 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. 在JSF中使用Ajax非常简单而优雅,但是由于调试限制,您不应该滥用Ajax。

HTML page Fragment : HTML页面片段:

 <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 : 支持bean片段:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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