jboss rich face 从3.3.3开始支持JSF 2.0 但是对JSF2.0的内建FACLET不支持。下面展示如何在JSF2.0中使用rich face
首先配置web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<!-- 用于 JSF 2.0 的配置 start-->
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<!-- 设置 JSF 页面文件的默认后缀 -->
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<!-- end -->
<!-- 用于JBOSS richface 的 配置 start -->
<context-param>
<param-name>org.richfaces.SKIN</param-name>
<param-value>blueSky</param-value>
</context-param>
<!-- Making the RichFaces skin spread to standard HTML controls -->
<context-param>
<param-name>org.richfaces.CONTROL_SKINNING</param-name>
<param-value>enable</param-value>
</context-param>
<!-- Turn off the VDL viewhandler with the following context-param in web.xml
关闭 VDL(JSF2.0内建的FACLET)如果没有这一句,会报出一个NoSuchMethod 异常.-->
<context-param>
<param-name>javax.faces.DISABLE_FACELET_JSF_VIEWHANDLER</param-name>
<param-value>true</param-value>
</context-param>
<!--
RichFaces 需要知道应用程序中将使用 Facelet。这些元素执行这个任务,并有效地替换 faces-config.xml 中常规的 Facelets 条目。注意,Facelets 视图处理程序类是 com.sun.facelets.FaceletViewHandler。
-->
<context-param>
<param-name>org.ajax4jsf.VIEW_HANDLERS</param-name>
<param-value>com.sun.facelets.FaceletViewHandler</param-value>
</context-param>
<!-- Defining and mapping the RichFaces filter -->
<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>
<!-- end -->
<welcome-file-list>
<welcome-file>hello.jsf</welcome-file>
</welcome-file-list>
</web-app>
接下来是faces-config.xml 定义一个hello的managementben
<?xml version="1.0"?>
<faces-config xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
version="2.0">
<!-- Empty for now. Your entries will go here. But even if you have no entries
in faces-config.xml, you are required to have a valid faces-config.xml file
with legal start and end tags. From JSF 2.0 tutorial at http://www.coreservlets.com/JSF-Tutorial/jsf2/ -->
<managed-bean>
<managed-bean-name>hello</managed-bean-name>
<managed-bean-class>com.richface.mbeans.HelloBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
<navigation-rule>
<from-view-id>/hello.xhtml</from-view-id>
<navigation-case>
<to-view-id>/show.xhtml</to-view-id>
<from-outcome>success</from-outcome>
</navigation-case>
</navigation-rule>
</faces-config>
JSF的页面文件hello.xhtml,其后缀xhtml和web中的配置对应。
<!-- 设置 JSF 页面文件的默认后缀 -->
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
然后编写页面文件
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich">
<head></head>
<body>
<h:form>
<rich:calendar name="Calendar" id="CalendarID"
value="#{hello.current}">
</rich:calendar>
<h:commandButton value="submit" action="#{hello.sayHello}"></h:commandButton>
</h:form>
</body>
</html>
接下来,编写managebean的代码
package com.richface.mbeans;
import java.util.Date;
public class HelloBean {
private Date current;
/**
* @return the current
*/
public Date getCurrent() {
return current;
}
/**
* @param current the current to set
*/
public void setCurrent(Date current) {
this.current = current;
}
public String sayHello(){
System.out.println("hello"+current.toLocaleString());
return "success";
}
}
最后部署到tomcat上就OK了。
分享到:
相关推荐
JSF2.0实战 - 9、自定义Filter处理资源文件依赖关系源代码
JSF2.0 自带的ajax实现很方便, 有多个工程可演示,必须在Tomcat6,jboss5,glassfish3才支持JSF2.0
jboss-ajax4jsf-1.1.1-src 具体自己看吧
本系列将以两个例子来讲解jsf的基本开发,第一个例子当然是hello world。目前可用的jsf ide不多,ibm要到06年才能放出支持jsf的wtp版本。所以我们的例子基本以手写为主,这样也能让我们有更清楚的认识,同时推荐目前...
虽然只是小版本的升级,但对于希望在JSF应用中使用HTML5技术的开发人员而言,JSF 2.2带来的更新很重要,尤其是pass through能力,它允许在JSF组件不知情的情况下传递HTML属性。 HTML5中增加了很多新特性,其中有些...
官方离线安装包,亲测可用
Jboss_Seam_2.0中文手册
helloworld:Helloworld 示例添加一名作者级别:初学者技术:CDI、Servlet 总结:基本示例,可用于验证服务器是否已正确配置和运行目标产品:EAP 产品版本:EAP 6.1、EAP 6.2 来源: : 它是什么? 此示例演示了CDI ...
HelloWorld helloworld = (HelloWorld) ctx.lookup("HelloWorldBean/remote"); out.println(helloworld.SayHello("佛山人")); 5.用ant或eclipse,把客户端文件打成war包,发布到jboss上 6.输入...
[TipTec Development] JSF & Facelets & JBoss Seam 核心技术 (英文版) [TipTec Development] Essential JSF, Facelets & JBoss Seam (E-Book) ☆ 出版信息:☆ [作者信息] Kent Ka Iok Tong [出版机构] TipTec ...
jboss-ajax4jsf-1.1.1-bin.zip
jboss-seam2.0文档.rar,希望大家能够喜欢,谢谢大家的支持,嘿嘿
EJB3.0+Struts2.0+Jboss Enterprise Application Project 示例 用jboss数据源可连接mysql ms-sql oracle 本地远程接口用单态模式实现
经典JAVA EE企业应用实战基于WEBLOGIC JBOSS的JSF+EJB 3+JPA整合开发——源码.part1 其他部分详见我的上传列表,全部分卷下载完成才能解压。 本书介绍了Java EE规范的三大主要规范JSF、EJB 3和JPA,其中JSF是Sun...
中文名: 经典Java EE企业应用实战--基于WebLogic/JBoss的JSF+EJB 3+JPA整合开发 原名: 经典Java EE企业应用实战--基于WebLogic/JBoss的JSF+EJB 3+JPA整合开发 作者: 李刚 资源格式: PDF 版本: 第一版 出版社: 电子...
seam2相关的api,包括满江红翻译的中文文档,该文档经过处理,可以按照标题进行索引。
JBoss Messaging 2.0
jboss服务器配置https环境的详细方法
这是一个HELLOWORLD程序,方便入门!