java.lang.IllegalStateException:在呈现响应后非法尝试设置 ViewHandler [英] java.lang.IllegalStateException: Illegal attempt to set ViewHandler after a response has been rendered
问题描述
我的 Java EE Web 应用程序在 Glassfish 2.1 上运行良好.现在我想迁移到 Glassfish 3.1.1,但在成功部署 war 文件后,出现以下错误:
My Java EE web application is working fine with Glassfish 2.1. Now I want to migrate to Glassfish 3.1.1, but after a successful deployment of the war file it gives following error:
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.
我的应用程序使用以下框架.
My application uses following frameworks.
- Spring 框架 3.0.2
- JSF 2.0
- RichFaces 3.3.3 最终版
它是用 JDK 1.6 编译的.
It's compiled with JDK 1.6.
这个问题是怎么引起的,我该如何解决?
How is this problem caused and how can I solve it?
编辑
我遵循了此处
我对richfaces的依赖如下:-
my dependencies for richfaces are as follow:-
<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 依赖项是
my jsf dependencies are
<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 中添加上下文参数如下:-
added context param in web.xml as follow:-
<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 版修改我的应用程序描述符,例如:
modified my application descriptor with version 2.5 like:
<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中的如下:-
my in faces-config is as follow:-
<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>
应用程序部署成功,但之后我在浏览器中启动应用程序时收到类转换异常错误:
Application get deployed successfully but after that i am getting error of class cast exception at the time starting an application in browser :
服务器日志如下:
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)
我该如何解决这个问题??
how can i resolve this??
推荐答案
java.lang.IllegalStateException:在呈现响应后非法尝试设置 ViewHandler.
java.lang.IllegalStateException: Illegal attempt to set ViewHandler after a response has been rendered.
这是在 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 取代.
This is a typical error message when you use a JSF 1.2 targeted component library on a JSF 2.x environment. RichFaces 3.3.x is designed for JSF 1.2, but Glassfish 3.1 ships with JSF 2.1 instead of JSF 1.2 as in Glassfish 2.1. In JSF 2 there are quite a lot of changes in the area of view handling, because JSP has been deprecated and replaced by Facelets.
RichFaces 有一个关于如何在 JSF 2 环境中安装和配置 RichFaces 3.3.3 的优秀指南:RichFaces 3.3.3 和 JSF 2.0.解决此特定异常的关键步骤是添加以下上下文参数,以禁用 JSF 2 Facelets 视图处理程序:
RichFaces has an excellent guide how to install and configure RichFaces 3.3.3 in a JSF 2 environment: RichFaces 3.3.3 and JSF 2.0. The key step to solve this particular exception is adding the following context parameter which disables the JSF 2 Facelets view handler:
<context-param>
<param-name>javax.faces.DISABLE_FACELET_JSF_VIEWHANDLER</param-name>
<param-value>true</param-value>
</context-param>
但还需要完成更多步骤.仔细阅读指南.
But more steps needs to be done as well. Read the guide thoroughly.
这篇关于java.lang.IllegalStateException:在呈现响应后非法尝试设置 ViewHandler的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!