当前位置: 代码迷 >> JavaScript >> 施用Eclipse 开发 Richfaces3.3.3 Final+jsf2.0 的基本配置
  详细解决方案

施用Eclipse 开发 Richfaces3.3.3 Final+jsf2.0 的基本配置

热度:681   发布时间:2012-09-22 21:54:54.0
使用Eclipse 开发 Richfaces3.3.3 Final+jsf2.0 的基本配置
首先,需要下载最新的Eclipse3.6 helio 因为 Galieo 版对.xhtml模板支持不是很好,而JSF2.0的界面使用Facelets 。下载了Helio后新建立Dynamic Web Project 接着修改web.xml
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5"
 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> 
	<description>Richfaces Components demo</description>
	<display-name>richfaces-demo</display-name>
	<context-param>
		<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
		<param-value>.xhtml</param-value>
	</context-param>
	<context-param>
		<param-name>facelets.REFRESH_PERIOD</param-name>
		<param-value>2</param-value>
	</context-param>
	<context-param>
		<param-name>facelets.DEVELOPMENT</param-name>
		<param-value>true</param-value>
	</context-param>
	<context-param>
		<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
		<param-value>server</param-value>
	</context-param>
	<context-param>
		<param-name>com.sun.faces.validateXml</param-name>
		<param-value>true</param-value>
	</context-param>
	<context-param>
		<param-name>com.sun.faces.verifyObjects</param-name>
		<param-value>false</param-value>
	</context-param>
	<context-param>
		<param-name>org.ajax4jsf.SKIN</param-name>
		<param-value>blueSky</param-value>
	</context-param>
	
	<context-param>
		<param-name>org.ajax4jsf.COMPRESS_SCRIPT</param-name>
		<param-value>true</param-value>
	</context-param>
	<context-param>
		<param-name>org.ajax4jsf.COMPRESS_STYLE</param-name>
		<param-value>true</param-value>
	</context-param>
	<context-param>
		<param-name>org.ajax4jsf.xmlparser.ORDER</param-name>
		<param-value>NEKO, TIDY</param-value>
	</context-param>
	<context-param>
		<param-name>org.richfaces.CONTROL_SKINNING</param-name>
		<param-value>enable</param-value>
	</context-param>
	<context-param>
		<param-name>org.richfaces.LoadStyleStrategy</param-name>
		<param-value>ALL</param-value>
	</context-param>
	<context-param>
		<param-name>org.richfaces.LoadScriptStrategy</param-name>
		<param-value>ALL</param-value>
	</context-param>
	<context-param>
		<param-name>javax.faces.DISABLE_FACELET_JSF_VIEWHANDLER</param-name>
		<param-value>true</param-value>
	</context-param>
	 <context-param>
		<param-name>org.ajax4jsf.handleViewExpiredOnClient</param-name> 
		<param-value>true</param-value> 	
	 </context-param> 
	

	<servlet>
		<servlet-name>Faces Servlet</servlet-name>
		<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
		<load-on-startup>1</load-on-startup>
	</servlet>
	<servlet-mapping>
		<servlet-name>Faces Servlet</servlet-name>
		<url-pattern>*.xhtml</url-pattern> 
	</servlet-mapping>
	<login-config>
		<auth-method>BASIC</auth-method>
	</login-config>
</web-app>

注意
<context-param>
		<param-name>org.ajax4jsf.VIEW_HANDLERS</param-name>
		<param-value>com.sun.facelets.FaceletViewHandler</param-value>
	</context-param>

是不需要的。
RichFaces 3.3.3 does not support JSF 2 built-in facelets (VDL)
Facelets 1.1.15 should still be used because of dependencies in RichFaces from the Tag Handlers classes.
RichFaces 3.3.3 不支持jsf2内置的VIEWHANDLER,仍然需要 jsf-facelets jar所包含的。

对于以下情况
com.sun.facelets.tag.TagException: /main.xhtml @8,57 <h:head> Tag Library supports namespace: http://java.sun.com/jsf/html, but no tag was defined for name: head. 或者是 <h:body>
似乎没有更好的解决办法,只能放弃使用h标签,而直接使用html.也就是说用<body>代替<h:body>
如果要使用Annotations Scanning
还需要将faces-config的version设置为"2.0"
faces-config
<?xml version='1.0' encoding='UTF-8'?>

<!-- =========== FULL CONFIGURATION FILE ================================== -->

<faces-config version="2.0"
    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">
 <application>
    <view-handler>
      com.sun.facelets.FaceletViewHandler
    </view-handler>
  <navigation-handler>org.richfaces.ui.application.StateNavigationHandler</navigation-handler>
  <el-resolver>org.richfaces.el.StateELResolver</el-resolver>
  <locale-config>
   <default-locale>en</default-locale>
   <supported-locale>en</supported-locale>
  </locale-config>
 </application>

</faces-config>


接下来是导入包。
直接以图片方式给出


注意如果不添加jstl.jar和standard.jar会抛
java.lang.NoClassDefFoundError: javax/servlet/jsp/jstl/core/Config

下载地址http://jakarta.apache.org/site/downloads/downloads_taglibs-standard.cgi 我用的是1.1.2
  相关解决方案