java.lang.IllegalStateException:在呈现响应之后非法尝试设置ViewHandler [英] java.lang.IllegalStateException: Illegal attempt to set ViewHandler after a response has been rendered

查看:551
本文介绍了java.lang.IllegalStateException:在呈现响应之后非法尝试设置ViewHandler的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Java EE web应用程序在Glassfish 2.1中运行正常。现在我想迁移到Glassfish 3.1.1,但是在成功部署war文件后,它会出现以下错误:

 警告:ApplicationDispatcher [/ Myapp] PWC1231:servlet的Servlet.service()Faces Servlet抛出异常
java.lang.IllegalStateException:在呈现响应后非法尝试设置ViewHandler。

我的应用程序使用以下框架:


  • Spring Framework 3.0.2

  • JSF 2.0

  • RichFaces 3.3.3 Final



它是使用JDK 1.6编译的。



这个问题是如何造成的?我该如何解决它?

>

编辑



我遵循了这里



我对richfaces的依赖关系如下所示: -

 < dependency> 
< groupId> org.richfaces.framework< / groupId>
< artifactId> richfaces-api< / artifactId>
< version> 3.3.3.Final< / version>
< /依赖关系>
< dependency>
< groupId> org.richfaces.framework< / groupId>
< artifactId> richfaces-impl-jsf2< / artifactId>
< version> 3.3.3.Final< / version>
< /依赖关系>
< dependency>
< groupId> org.richfaces.ui< / groupId>
< artifactId> richfaces-ui< / artifactId>
< version> 3.3.3.Final< / version>
< /依赖关系>

我的jsf依赖关系是

 < dependency> 
< groupId> com.sun.faces< / groupId>
< artifactId> jsf-api< / artifactId>
< version> 2.0.2< / version>
< /依赖关系>
< dependency>
< groupId> com.sun.faces< / groupId>
< artifactId> jsf-impl< / artifactId>
< version> 2.0.2< / version>
< /依赖关系>

在web.xml中添加了上下文参数,如下所示: - $ / b
$ b

 < 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< /参数值>
< / context-param>

用2.5版本修改了我的应用程序描述符:

 < web-app version =2.5xmlns =http://java.sun.com/xml/ns/j2eexmlns:xsi =http:// www.w3.org/2001/XMLSchema-instancexsi: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已成功部署在21,635毫秒。 
SEVERE:错误渲染视图[/login.xhtml]
javax.faces.FacesException:java.lang.ClassCastException:java.lang.String无法转换为javax.faces.component.UIComponent
在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随GlassFish 2.1一起提供JSF 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视图处理程序的上下文参数:

 <上下文-param> 
< param-name> javax.faces.DISABLE_FACELET_JSF_VIEWHANDLER< / param-name>
< param-value> true< /参数值>
< / context-param>

但是还需要完成更多步骤。彻底阅读指南。


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 Framework 3.0.2
  • JSF 2.0
  • RichFaces 3.3.3 Final

It's compiled with JDK 1.6.

How is this problem caused and how can I solve it?

EDIT

I have followed the modifications provided here

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>

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>

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>

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">

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 :

server log is as follow:

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: Illegal attempt to set ViewHandler after a response has been rendered.

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 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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆