我的Java EE Web应用程序在Glassfish 2.1上运行良好。现在,我想迁移到Glassfish 3.1.1,但是在成功部署war文件后,它出现以下错误:
WARNING: ApplicationDispatcher[/Myapp] PWC1231: Servlet.service() for servlet Faces Servlet threw exception java.lang.IllegalStateException: Illegal attempt to set ViewHandler after a response has been rendered.
我的应用程序使用以下框架。
它是用JDK 1.6编译的。
这个问题是怎么引起的,我该如何解决?
编辑
我已遵循此处提供的修改
我对richfaces的依赖如下:
<dependency> <groupId>org.richfaces.framework</groupId> <artifactId>richfaces-api</artifactId> <version>3.3.3.Final</version> </dependency> <dependency> <groupId>org.richfaces.framework</groupId> <artifactId>richfaces-impl-jsf2</artifactId> <version>3.3.3.Final</version> </dependency> <dependency> <groupId>org.richfaces.ui</groupId> <artifactId>richfaces-ui</artifactId> <version>3.3.3.Final</version> </dependency>
我的jsf依赖项是
<dependency> <groupId>com.sun.faces</groupId> <artifactId>jsf-api</artifactId> <version>2.0.2</version> </dependency> <dependency> <groupId>com.sun.faces</groupId> <artifactId>jsf-impl</artifactId> <version>2.0.2</version> </dependency>
在web.xml中添加了上下文参数,如下所示:
<context-param> <param-name>org.ajax4jsf.VIEW_HANDLERS</param-name> <param-value>com.sun.facelets.FaceletViewHandler</param-value> </context-param> <context-param> <param-name>javax.faces.DISABLE_FACELET_JSF_VIEWHANDLER</param-name> <param-value>true</param-value> </context-param>
用2.5版本修改了我的应用程序描述符,例如:
<web-app version="2.5" 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/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
我的 ****在faces-config中如下:
<application> <navigation-handler > org.navigation.CustomNavigationHandler </navigation-handler> <view-handler> org.ajax4jsf.application.AjaxViewHandler </view-handler> <!-- <view-handler> com.sun.facelets.FaceletViewHandler </view-handler>--> <variable-resolver>org.springframework.web.jsf.DelegatingVariableResolver</variable-resolver> <message-bundle>MyMessages</message-bundle> </application>
应用程序已成功部署,但此后在浏览器中启动应用程序时出现类强制转换异常错误:
服务器日志如下:
INFO: myApp was successfully deployed in 21,635 milliseconds. SEVERE: Error Rendering View[/login.xhtml] javax.faces.FacesException: java.lang.ClassCastException: java.lang.String cannot be cast to javax.faces.component.UIComponent at com.sun.faces.application.ApplicationImpl.createComponentApplyAnnotations(ApplicationImpl.java:1923)
我该如何解决呢?
java.lang.IllegalStateException:呈现响应后,非法尝试设置ViewHandler。
当您在JSF 2.x环境中使用JSF 1.2目标组件库时,这是典型的错误消息。RichFaces 3.3.x是为JSF 1.2设计的,但是Glassfish 3.1随JSF 2.1一起提供,而不是像Glassfish 2.1中的JSF 1.2。在JSF 2中,视图处理领域发生了许多变化,因为JSP已被弃用并由Facelets代替。
RichFaces有一个很好的指南,介绍如何在JSF 2环境中安装和配置RichFaces 3.3.3:RichFaces 3.3.3和JSF 2.0。解决此特殊异常的关键步骤是添加以下上下文参数,该参数禁用JSF 2 Facelets视图处理程序:
<context-param> <param-name>javax.faces.DISABLE_FACELET_JSF_VIEWHANDLER</param-name> <param-value>true</param-value> </context-param>
但是,还需要执行更多步骤。彻底阅读指南。