一、准备工作
1.下载文件:
http://labs.jboss.com/jbossrichfaces/downloads
当前最新的版本是3.10,9月12日发布的。
2.安装。
解压后,将"richfaces-api-3.1.0.jar" , "richfaces-impl-3.1.0.jar" , "richfaces-ui-3.1.0.jar"这三个文件拷贝到WEB-INFO/lib目录下,
修改web.xml,应该是这个样子:
- <?xml version="1.0"?>
- <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
- http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
- <display-name>togglePanel</display-name>
- <context-param>
- <param-name>org.richfaces.SKIN</param-name>
- <param-value>blueSky</param-value>
- </context-param>
- <context-param>
- <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
- <param-value>server</param-value>
- </context-param>
- <filter>
- <display-name>RichFaces Filter</display-name>
- <filter-name>richfaces</filter-name>
- <filter-class>org.ajax4jsf.Filter</filter-class>
- </filter>
- <filter-mapping>
- <filter-name>richfaces</filter-name>
- <servlet-name>Faces Servlet</servlet-name>
- <dispatcher>REQUEST</dispatcher>
- <dispatcher>FORWARD</dispatcher>
- <dispatcher>INCLUDE</dispatcher>
- </filter-mapping>
- <listener>
- <listener-class>
- com.sun.faces.config.ConfigureListener
- </listener-class>
- </listener>
- <!-- Faces Servlet -->
- <servlet>
- <servlet-name>Faces Servlet</servlet-name>
- <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
- <load-on-startup>1</load-on-startup>
- </servlet>
- <!-- Faces Servlet Mapping -->
- <servlet-mapping>
- <servlet-name>Faces Servlet</servlet-name>
- <url-pattern>*.jsf</url-pattern>
- </servlet-mapping>
- <welcome-file-list>
- <welcome-file>index.html</welcome-file>
- <welcome-file>index.htm</welcome-file>
- <welcome-file>index.jsp</welcome-file>
- <welcome-file>default.html</welcome-file>
- <welcome-file>default.htm</welcome-file>
- <welcome-file>default.jsp</welcome-file>
- </welcome-file-list>
- </web-app>
在每个jsp文件中添加如下头文件:
- <%@ taglib uri="http://richfaces.org/a4j" prefix="a4j"%>
- <%@ taglib uri="http://richfaces.org/rich" prefix="rich"%>
如果是xhtml,则添加如下:
- <xmlns:a4jxmlns:a4j="http://richfaces.org/a4j">
- <xmlns:richxmlns:rich="http://richfaces.org/rich">
这样一个ajax4jsf就可以使用了。
二、一个简单的例子
1.jsp
Here is the necessary page (echo.jsp):
- <%@ taglib uri="http://richfaces.org/a4j" prefix="a4j"%>
- <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
- <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
- <html>
- <head>
- <title>repeater title>
- head>
- <body>
- <f:view>
- <h:form>
- <rich:panel header="Simple Echo">
- <h:inputText size="50" value="#{bean.text}" >
- <a4j:support event="onkeyup" reRender="rep"/>
- h:inputText>
- <h:outputText value="#{bean.text}" id="rep"/>
- rich:panel>
- h:form>
- f:view>
- body>
- html>
2.Data Bean
- package demo;
- public class Bean {
- private String text;
- public Bean() {
- }
- public String getText() {
- return text;
- }
- public void setText(String text) {
- this.text = text;
- }
- }
3.faces-config.xml
- xml version="1.0" encoding="UTF-8"?>
- Config 1.1//EN"
- "http://java.sun.com/dtd/web-facesconfig_1_1.dtd">
- <faces-config>
- <managed-bean>
- <managed-bean-name>beanmanaged-bean-name>
- <managed-bean-class>demo.Beanmanaged-bean-class>
- <managed-bean-scope>requestmanaged-bean-scope>
- <managed-property>
- <property-name>textproperty-name>
- <value/>
- managed-property>
- managed-bean>
- faces-config>
4.web.xml
- xml version="1.0"?>
- <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
- http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
- <display-name>a4jEchoTextdisplay-name>
- <context-param>
- <param-name>org.richfaces.SKINparam-name>
- <param-value>blueSkyparam-value>
- context-param>
- <context-param>
- <param-name>javax.faces.STATE_SAVING_METHODparam-name>
- <param-value>serverparam-value>
- context-param>
- <filter>
- <display-name>RichFaces Filterdisplay-name>
- <filter-name>richfacesfilter-name>
- <filter-class>org.ajax4jsf.Filterfilter-class>
- filter>
- <filter-mapping>
- <filter-name>richfacesfilter-name>
- <servlet-name>Faces Servletservlet-name>
- <dispatcher>REQUESTdispatcher>
- <dispatcher>FORWARDdispatcher>
- <dispatcher>INCLUDEdispatcher>
- filter-map>
- <listener>
- <listener-class>com.sun.faces.config.ConfigureListenerlistener-class>
- listener>
- <servlet>
- <servlet-name>Faces Servletservlet-name>
- <servlet-class>javax.faces.webapp.FacesServletservlet-class>
- <load-on-startup>1load-on-startup>
- servlet>
- <servlet-mapping>
- <servlet-name>Faces Servletservlet-name>
- <url-pattern>*.jsfurl-pattern>
- servlet-mapping>
- <login-config>
- <auth-method>BASICauth-method>
- login-config>
- web-app>
这样,一个ajax4jsf 就可以运行了