目录
1 RichFaces基础 2
1.1 环境搭建 2
1.2 默认皮肤更换 3
1.3 解决MyEclipse没有正常部署项目的问题 3
2 组件 4
2.1 a4j:ajaxListener 4
2.1.1 作用 4
2.1.2 编写事件监听类 4
2.1.3 编写页面 4
2.2 a4j:commandButton 5
2.2.1 页面 5
2.2.2 Bean类 5
2.3 a4j:commandLink 6
2.3.1 页面 6
2.3.2 Bean类 7
2.4 rich:dataGrid 8
2.4.1 页面 8
2.4.2 Bean类 9
2.4.3 rich:dataList 11
2.5 </rich:dataTable> 14
2.5.1 页面 14
2.5.2 Bean类 15
2.6 rich:dropDownMenu 17
2.6.1 样子 17
2.6.2 页面 17
1 RichFaces基础
1.1 环境搭建
1. 首先搭建JSF环境。
2. 将RichFaces的包考到ClassPath下。
3. 在Web.xml中将节点写成:
<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">
4. 在Web.xml中添加:
<context-param>
<param-name>org.richfaces.SKIN</param-name>
<param-value>blueSky</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>
1.2 默认皮肤更换
<context-param>
<param-name>org.richfaces.SKIN</param-name>
<param-value>blueSky</param-value>
</context-param>
可选择的默认皮肤有:
• DEFAULT
• plain
• emeraldTown
• blueSky
• wine
• japanCherry
• ruby
• classic
• deepMarine
1.3 解决MyEclipse没有正常部署项目的问题
有时,没有部署,但又不报错,可以:
将Project从Server中Remove,然后在Deploy。
2 组件
2.1 a4j:ajaxListener
2.1.1 作用
发request到后台类中。
2.1.2 编写事件监听类
package action_listener;
import org.ajax4jsf.event.AjaxEvent;
import org.ajax4jsf.event.AjaxListener;
public class CommandListener implements AjaxListener {
public void processAjax(AjaxEvent arg0) {
System.out.println( "\nI am here!" );
}
}
2.1.3 编写页面
<%@ taglib uri="http://richfaces.org/a4j" prefix="a4j"%>
<%@ taglib uri="http://richfaces.org/rich" prefix="rich"%>
<%@ 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">
<a4j:commandLink id="cLink" value="Hi, this is Eric!">
<a4j:ajaxListener type="action_listener.CommandListener" />
</a4j:commandLink>
</rich:panel>
</h:form>
</f:view>
</body>
</html>
2.2 a4j:commandButton
2.2.1 页面
<%@ taglib uri="http://richfaces.org/a4j" prefix="a4j"%>
<%@ taglib uri="http://richfaces.org/rich" prefix="rich"%>
<%@ 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="#{commandButtonBean.name}">
<a4j:support event="onkeyup" reRender="rep" />
</h:inputText>
<a4j:commandButton reRender="rep" action="#{commandButtonBean.callEric}" value="Call Eric"/>
<h:outputText value="#{commandButtonBean.ericMsg}" id="rep" />
</rich:panel>
</h:form>
</f:view>
</body>
</html>
2.2.2 Bean类
package command_button;
import java.io.Serializable;
public class Bean implements Serializable {
private String ericMsg = "";
private String name = "";
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getEricMsg() {
return ericMsg;
}
public void setEricMsg(String ericMsg) {
this.ericMsg = ericMsg;
}
public void callEric() {
this.ericMsg = this.name + " is calling Eric!";
this.name = this.ericMsg;
System.out.println( this.ericMsg );
}
public void clear() {
this.ericMsg = "";
this.name = "";
}
}
2.3 a4j:commandLink
2.3.1 页面
<%@ taglib uri="http://richfaces.org/a4j" prefix="a4j"%>
<%@ taglib uri="http://richfaces.org/rich" prefix="rich"%>
<%@ 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