Java.lang.IllegalStateException: Invalid attempt to set ViewHandler after response has been received
My Java EE web app works fine with Glassfish 2.1. Now I want to upgrade to Glassfish 3.1.1, but after successfully deploying the war file, it gives the 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 the following frameworks.
- Spring Framework 3.0.2
- JSF 2.0
- RichFaces 3.3.3 Final
It is compiled with JDK 1.6.
How does this problem occur and how can I solve it?
EDIT
I followed the changes made here
My dependencies for richfaces are as follows: -
<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
<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 parameter to web.xml like this: -
<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>
changed 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 looks like this: -
<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>
The app deploys successfully, but after that I get a class exception error when running the app in the browser:
The server log looks like this:
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 solve this problem?
source to share
java.lang.IllegalStateException: Invalid attempt to set ViewHandler after receiving response.
This is a typical error message when using the target JSF 1.2 component library in a JSF 2.x environment. RichFaces 3.3.x targets JSF 1.2, but Glassfish 3.1 ships with JSF 2.1 instead of JSF 1.2 as in Glassfish 2.1. There are quite a few changes in view handling in JSF 2 as JSP is deprecated and replaced by Facelets.
RichFaces has a great tutorial on how to install and configure RichFaces 3.3.3 in JSF 2: RichFaces 3.3.3 and JSF 2.0 . The key step to resolve this particular exception is to add 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 there are a few more steps to be taken. Read the entire manual.
source to share
I had to remove the Ajax4jsf library from my application before I could clear this error. Obviously the Ajax4jsf library is not JSF 2.0 compliant.
I found this here.
Porting JSF 1.1 from Ajax4jsf-1.x to JSF2
source to share