title: java.lang.IllegalStateException: Illegal attempt to set ViewHandler after a response has been rendered
body: <p>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:</p>
  
  <pre><code>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.
  </code></pre>
  
  <p>My application uses following frameworks.</p>
  
  <ul>
  <li>Spring Framework 3.0.2</li>
  <li>JSF 2.0</li>
  <li>RichFaces 3.3.3 Final</li>
  </ul>
  
  <p>It's compiled with JDK 1.6.</p>
  
  <p>How is this problem caused and how can I solve it?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I have followed the modifications provided <a href="https://community.jboss.org/wiki/RichFaces333AndJSF20" rel="nofollow">here</a></p>
  
  <p>my dependencies for richfaces are as follow:-</p>
  
  <pre><code>   &lt;dependency&gt;
          &lt;groupId&gt;org.richfaces.framework&lt;/groupId&gt;
          &lt;artifactId&gt;richfaces-api&lt;/artifactId&gt;
          &lt;version&gt;3.3.3.Final&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.richfaces.framework&lt;/groupId&gt;
          &lt;artifactId&gt;richfaces-impl-jsf2&lt;/artifactId&gt;
          &lt;version&gt;3.3.3.Final&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.richfaces.ui&lt;/groupId&gt;
          &lt;artifactId&gt;richfaces-ui&lt;/artifactId&gt;
          &lt;version&gt;3.3.3.Final&lt;/version&gt;
      &lt;/dependency&gt;
  </code></pre>
  
  <p>my jsf dependencies are </p>
  
  <pre><code>        &lt;dependency&gt;
              &lt;groupId&gt;com.sun.faces&lt;/groupId&gt; 
              &lt;artifactId&gt;jsf-api&lt;/artifactId&gt; 
              &lt;version&gt;2.0.2&lt;/version&gt; 
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.sun.faces&lt;/groupId&gt; 
              &lt;artifactId&gt;jsf-impl&lt;/artifactId&gt; 
              &lt;version&gt;2.0.2&lt;/version&gt; 
          &lt;/dependency&gt;
  </code></pre>
  
  <p>added context param in web.xml as follow:-</p>
  
  <pre><code>&lt;context-param&gt;
      &lt;param-name&gt;org.ajax4jsf.VIEW_HANDLERS&lt;/param-name&gt;
      &lt;param-value&gt;com.sun.facelets.FaceletViewHandler&lt;/param-value&gt;
  &lt;/context-param&gt;
  &lt;context-param&gt;
      &lt;param-name&gt;javax.faces.DISABLE_FACELET_JSF_VIEWHANDLER&lt;/param-name&gt;
      &lt;param-value&gt;true&lt;/param-value&gt;
  &lt;/context-param&gt;
  </code></pre>
  
  <p>modified my application descriptor with version 2.5 like:</p>
  
  <pre><code>&lt;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"&gt;
  </code></pre>
  
  <p>my <strong></strong> in faces-config is as follow:-</p>
  
  <pre><code> &lt;application&gt;
          &lt;navigation-handler &gt;
              org.navigation.CustomNavigationHandler
          &lt;/navigation-handler&gt;
  
          &lt;view-handler&gt;
              org.ajax4jsf.application.AjaxViewHandler
          &lt;/view-handler&gt;
  &lt;!--        &lt;view-handler&gt;
              com.sun.facelets.FaceletViewHandler
          &lt;/view-handler&gt;--&gt;
          &lt;variable-resolver&gt;org.springframework.web.jsf.DelegatingVariableResolver&lt;/variable-resolver&gt;
          &lt;message-bundle&gt;MyMessages&lt;/message-bundle&gt;
      &lt;/application&gt;
  </code></pre>
  
  <p>Application get deployed successfully but after that i am getting error of class cast exception at the time starting an application in browser :</p>
  
  <p>server log is as follow:</p>
  
  <pre><code>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)
  </code></pre>
  
  <p>how can i resolve this??</p>