在集成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:
- <filter>
- <filter-name>sitemeshfilter-name>
- <filter-class>net.climbingrose.sitemesh.filter.SMInitFilterfilter-class>
- filter>
- <filter-mapping>
- <filter-name>sitemeshfilter-name>
- <url-pattern>/*url-pattern>
- filter-mapping>
+In your faces-config.xml:
- <view-handler>
- net.climbingrose.sitemesh.jsf.SMViewHandlerImp
- view-handler>
3.配置web.xml
我的web.xml配置如下:
- <!---->xml version="1.0" encoding="UTF-8"?>
- <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">
-
-
- <description>smrdescription>
-
- <context-param>
- <param-name>javax.faces.CONFIG_FILESparam-name>
- <param-value>/WEB-INF/examples-config.xmlparam-value>
-
- context-param>
-
- <context-param>
- <param-name>javax.faces.STATE_SAVING_METHODparam-name>
- <param-value>clientparam-value>
- context-param>
-
- <context-param>
- <param-name>com.sun.faces.validateXmlparam-name>
- <param-value>trueparam-value>
- context-param>
- <context-param>
- <param-name>com.sun.faces.verifyObjectsparam-name>
- <param-value>trueparam-value>
- context-param>
-
- <context-param>
- <param-name>org.ajax4jsf.COMPRESS_SCRIPTparam-name>
- <param-value>falseparam-value>
- context-param>
- <context-param>
- <param-name>org.ajax4jsf.xmlparser.ORDERparam-name>
- <param-value>NEKOparam-value>
- context-param>
-
- <filter>
- <filter-name>ajax4jsffilter-name>
- <filter-class>org.ajax4jsf.Filterfilter-class>
- filter>
-
- <filter>
- <filter-name>sitemeshfilter-name>
- <filter-class>net.climbingrose.sitemesh.filter.SMInitFilterfilter-class>
- filter>
-
- <filter-mapping>
- <filter-name>ajax4jsffilter-name>
- <servlet-name>Faces Servletservlet-name>
- <dispatcher>FORWARDdispatcher>
- <dispatcher>REQUESTdispatcher>
- <dispatcher>INCLUDEdispatcher>
- <dispatcher>ERRORdispatcher>
- filter-mapping>
-
- <filter-mapping>
- <filter-name>sitemeshfilter-name>
- <url-pattern>/*url-pattern>
- filter-mapping>
-
- <listener>
- <listener-class>org.apache.myfaces.webapp.StartupServletContextListenerlistener-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>/faces/*url-pattern>
- servlet-mapping>
-
-
-
- <servlet-mapping>
- <servlet-name>Faces Servletservlet-name>
- <url-pattern>*.jsfurl-pattern>
- servlet-mapping>
-
-
-
- <welcome-file-list>
- <welcome-file>index.jspwelcome-file>
- <welcome-file>index.htmlwelcome-file>
- welcome-file-list>
-
- web-app>
具体的原因,我就不具体说了。
下面是我的JSF 配置文件,可以参考:
- <!---->xml version="1.0"?>
-
- <!---->
- "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.0//EN"
- "http://java.sun.com/dtd/web-facesconfig_1_0.dtd" >
-
- <faces-config>
- <application>
- <view-handler>
- net.climbingrose.sitemesh.jsf.SMViewHandlerImp
- view-handler>
- application>
-
- <managed-bean>
- <managed-bean-name>helloWorldBackingmanaged-bean-name>
- <managed-bean-class>
- org.apache.myfaces.blank.HelloWorldBacking
- managed-bean-class>
- <managed-bean-scope>requestmanaged-bean-scope>
- managed-bean>
-
-
- <navigation-rule>
- <from-view-id>/helloWorld.jspfrom-view-id>
- <navigation-case>
- <from-outcome>successfrom-outcome>
- <to-view-id>/page2.jspto-view-id>
- navigation-case>
- navigation-rule>
-
-
- <navigation-rule>
- <from-view-id>/page2.jspfrom-view-id>
- <navigation-case>
- <from-outcome>backfrom-outcome>
- <to-view-id>/helloWorld.jspto-view-id>
- navigation-case>
- navigation-rule>
- 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