论坛首页 Java企业应用论坛

sitemesh,myfaces,richfaces 的集成解决方案

浏览 7847 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2007-09-27  

在集成sitemesh,myfaces,richfaces 时,会遇到各种问题,如:

 1.Could not invoke the service() method on servlet Faces Servlet. Exception thrown : javax.servlet.ServletException: org.apache.myfaces.webapp.webxml.WebXml.init must be called before!

2.java.lang.NoClassDefFoundError: Error while defining class: org.apache.myfaces.custom.autoupdatedatatable.AutoUpdateDataTable
This error indicates that the class: org.apache.myfaces.component.html.ext.HtmlDataTable
could not be located while defining the class: org.apache.myfaces.custom.autoupdatedatatable.AutoUpdateDataTable
This is often caused by having the class at a higher point in the classloader hierarchy

3.Servlet.service() for servlet Faces Servlet threw exception
java.lang.NullPointerException
诸如此类的问题,不一而足,我用的环境是Websphere Application Server 6.1,里面还面临着替换ibm的jsf ri问题,下面逐一解决:

1.在Websphere Application Server 6.1中去掉自带的RI,安装MyFaces RI

主要是改变应用的类加载策略,都改成PARANT_LAST,注意无论是EAR包的加载策略还是WAR的加载策略都需要改变,下面是一个更加详细的文档:       

Unlike Websphere 6.0, in Websphere 6.1 the JSF Sun RI is bundled together with several other WAS libraries in com.ibm.ws.webcontainer_2.0.0.jar, so removing the webspheres JSF API jars is not an option. The procedure below describes how to use MyFaces, TOMAHAWK (and even Tiles) on Websphere 6.1 by altering the module classloader policy to load classes using the application class loader first (thereby loading the MyFaces jars before the Sun RI jars). This procedure has been tested with MyFaces 1.1.3, TOMAHAWK 1.1.3, and Websphere 6.1.0.2.

1. Copy the MyFaces JSF jars and dependencies to WebApp lib (follow step 1 of the Websphere 6.0 Installation Guide without removing IBM jars below).

Make sure you do NOT copy commons-logging-1.0.4 jar (conflicts with the commons-logging jar already provided by Websphere) and also jsp-2.0.jar (which will cause a "com.ibm.ws.jsp.taglib.TldParser logParseErrorMessage: The JSP container failed to load the TagExtraInfo class" exception with JSF applications that use tiles).

2. Deploy the web application on WAS.
3. Alter the module classloader policy to application first.

Note that there are several ways to set the classloader policy in websphere (at the server, application, and module level). You need to set it at the module level as follows: Click on Enterprise Applications > Your application > Manage Modules > Your war file > Change Class loader order to "Classes loaded with application class loader first"

4. Start your application.

2,更换必要的jar包:

我使用的jar包如下:
commons-beanutils-1.7.0.jar
commons-codec-1.3.jar
commons-collections-3.2.jar
commons-digester-1.8.jar
commons-el-1.0.jar
commons-logging-1.0.4.jar
el-api.jar
el-ri.jar
jhighlight-1.0.jar
jstl-1.0.jar
myfaces-all-2005-10-25.jar
myfaces-api-1.1.5.jar
myfaces-impl-1.1.5.jar
nekohtml-0.9.5.jar
richfaces-api-3.1.0.jar
richfaces-impl-3.1.0.jar
richfaces-ui-3.1.0.jar
sandbox.jar
sitemesh-2.3.jar
tomahawk.jar
xercesImpl-2.4.0.jar

其中sitemesh这个包需要重新build,具体的方法如下(可以参照reference1):

你需要重新下载这个文件:SMViewHandler.zip ,也可以从本文的附件中下载,然后:
+You can drop the unzipped folder in sitemesh source folder and do a rebuild.(rebuild的时候需要添加myfaces的jar包到lib目录下,还需要添加log包,也可以直接使用附件中带的jar)
+Add the following to your web.xml:

  1. <filter>  
  2.         <filter-name>sitemeshfilter-name>  
  3.         <filter-class>net.climbingrose.sitemesh.filter.SMInitFilterfilter-class>  
  4.     filter>  
  5.     <filter-mapping>  
  6.         <filter-name>sitemeshfilter-name>  
  7.         <url-pattern>/*url-pattern>  
  8. filter-mapping>    


+In your faces-config.xml:

  1. <view-handler>  
  2. net.climbingrose.sitemesh.jsf.SMViewHandlerImp   
  3. view-handler>  

3.配置web.xml

我的web.xml配置如下:

  1. <!---->xml version="1.0" encoding="UTF-8"?>  
  2. <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"  
  3.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  4.     xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">  
  5.   
  6.   
  7.     <description>smrdescription>  
  8.   
  9.     <context-param>  
  10.         <param-name>javax.faces.CONFIG_FILESparam-name>  
  11.         <param-value>/WEB-INF/examples-config.xmlparam-value>  
  12.   
  13.     context-param>  
  14.   
  15.     <context-param>  
  16.         <param-name>javax.faces.STATE_SAVING_METHODparam-name>  
  17.         <param-value>clientparam-value>  
  18.     context-param>  
  19.   
  20.     <context-param>  
  21.         <param-name>com.sun.faces.validateXmlparam-name>  
  22.         <param-value>trueparam-value>  
  23.     context-param>  
  24.     <context-param>  
  25.         <param-name>com.sun.faces.verifyObjectsparam-name>  
  26.         <param-value>trueparam-value>  
  27.     context-param>  
  28.   
  29.     <context-param>  
  30.         <param-name>org.ajax4jsf.COMPRESS_SCRIPTparam-name>  
  31.         <param-value>falseparam-value>  
  32.     context-param>  
  33.     <context-param>  
  34.         <param-name>org.ajax4jsf.xmlparser.ORDERparam-name>  
  35.         <param-value>NEKOparam-value>  
  36.     context-param>  
  37.   
  38.     <filter>  
  39.         <filter-name>ajax4jsffilter-name>  
  40.         <filter-class>org.ajax4jsf.Filterfilter-class>  
  41.     filter>  
  42.        
  43.     <filter>  
  44.         <filter-name>sitemeshfilter-name>  
  45.         <filter-class>net.climbingrose.sitemesh.filter.SMInitFilterfilter-class>  
  46.     filter>  
  47.        
  48.     <filter-mapping>  
  49.         <filter-name>ajax4jsffilter-name>  
  50.         <servlet-name>Faces Servletservlet-name>  
  51.         <dispatcher>FORWARDdispatcher>  
  52.         <dispatcher>REQUESTdispatcher>  
  53.         <dispatcher>INCLUDEdispatcher>  
  54.         <dispatcher>ERRORdispatcher>  
  55.     filter-mapping>  
  56.        
  57.     <filter-mapping>  
  58.         <filter-name>sitemeshfilter-name>  
  59.         <url-pattern>/*url-pattern>  
  60.     filter-mapping>    
  61.        
  62.     <listener>      
  63.         <listener-class>org.apache.myfaces.webapp.StartupServletContextListenerlistener-class>      
  64.     listener>     
  65.     <!---->  
  66.     <servlet>  
  67.         <servlet-name>Faces Servletservlet-name>  
  68.         <servlet-class>javax.faces.webapp.FacesServletservlet-class>  
  69.         <load-on-startup>1load-on-startup>  
  70.     servlet>  
  71.   
  72.     <!---->  
  73.   
  74.     <!---->  
  75.   
  76.     <servlet-mapping>  
  77.         <servlet-name>Faces Servletservlet-name>  
  78.         <url-pattern>/faces/*url-pattern>  
  79.     servlet-mapping>  
  80.   
  81.   
  82.     <!---->  
  83.     <servlet-mapping>  
  84.         <servlet-name>Faces Servletservlet-name>  
  85.         <url-pattern>*.jsfurl-pattern>  
  86.     servlet-mapping>  
  87.   
  88.     <!---->  
  89.   
  90.     <welcome-file-list>  
  91.         <welcome-file>index.jspwelcome-file>  
  92.         <welcome-file>index.htmlwelcome-file>  
  93.     welcome-file-list>  
  94.   
  95. web-app>  
 

 具体的原因,我就不具体说了。

下面是我的JSF 配置文件,可以参考:

  1. <!---->xml version="1.0"?>  
  2.   
  3. <!---->
  4.   "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.0//EN"   
  5.   "http://java.sun.com/dtd/web-facesconfig_1_0.dtd" >  
  6.   
  7. <faces-config>  
  8.     <application>  
  9.         <view-handler>  
  10.             net.climbingrose.sitemesh.jsf.SMViewHandlerImp   
  11.         view-handler>  
  12.     application>  
  13.     <!---->  
  14.     <managed-bean>  
  15.         <managed-bean-name>helloWorldBackingmanaged-bean-name>  
  16.         <managed-bean-class>  
  17.             org.apache.myfaces.blank.HelloWorldBacking   
  18.         managed-bean-class>  
  19.         <managed-bean-scope>requestmanaged-bean-scope>  
  20.     managed-bean>  
  21.   
  22.     <!---->  
  23.     <navigation-rule>  
  24.         <from-view-id>/helloWorld.jspfrom-view-id>  
  25.         <navigation-case>  
  26.             <from-outcome>successfrom-outcome>  
  27.             <to-view-id>/page2.jspto-view-id>  
  28.         navigation-case>  
  29.     navigation-rule>  
  30.   
  31.     <!---->  
  32.     <navigation-rule>  
  33.         <from-view-id>/page2.jspfrom-view-id>  
  34.         <navigation-case>  
  35.             <from-outcome>backfrom-outcome>  
  36.             <to-view-id>/helloWorld.jspto-view-id>  
  37.         navigation-case>  
  38.     navigation-rule>  
  39. faces-config>  

 

 

 

 

Refrence:

1,http://jira.opensymphony.com/browse/SIM-201

2,http://java.chinaitlab.com/JBoss/390987.html

3,http://java.chinaitlab.com/JBoss/390987.html

 

  • sitemesh-2.3.jar (184.7 KB)
  • 描述: 已经编译好,可以直接使用
  • 下载次数: 107
   发表时间:2007-09-28  
不能用呀!老兄是一个空白页面。
0 请登录后投票
   发表时间:2007-09-29  
首先要确保sitemesh能运行,然后再加上myfaces,然后再加上richfaces。
0 请登录后投票
   发表时间:2007-10-09  
可以啊,但是这种方式不是很好,我们现在已经不采用这种方法了呵呵,
0 请登录后投票
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics