title: jsf Response already committed
body: <p>I'm working in JSF and trying to redirect a page if the user has already selected a language (I know that from a cookie).</p>
  
  <p>So I've set a listener :</p>
  
  <pre><code>&lt;f:event listener="#{languageSelectionController.checkSkipLanguageSelection}" type="preRenderView" /&gt;
  </code></pre>
  
  <p>that check if the cookie is present and if so redirect to the home page (without propose language choice page)</p>
  
  <pre><code> if (languageBean.isValidCookieDetected()) {
          FacesContext.getCurrentInstance().getApplication().getNavigationHandler().handleNavigation(FacesContext.getCurrentInstance(), "languageSelection.xhtml", "toHome");
      }
  </code></pre>
  
  <p>But I get an exception</p>
  
  <pre><code>java.lang.IllegalStateException: Response already committed
  at weblogic.servlet.internal.ServletResponseImpl.objectIfCommitted(ServletResponseImpl.java:1602)
  at weblogic.servlet.internal.ServletResponseImpl.sendRedirect(ServletResponseImpl.java:833)
  at com.sun.faces.context.ExternalContextImpl.redirect(ExternalContextImpl.java:576)
  at com.sun.faces.application.NavigationHandlerImpl.handleNavigation(NavigationHandlerImpl.java:182)
  </code></pre>
  
  <p>I've read the post <a href="https://stackoverflow.com/questions/14392361/jsf-response-already-committed-error">What exactly does &quot;Response already committed&quot; mean? How to handle exceptions then?</a> and try to raise the buffer size but it changes nothing.</p>
  
  <p>UDPATE :</p>
  
  <p>I've set a filter with the following code :</p>
  
  <pre><code>    HttpServletRequest httpServletRequest = (HttpServletRequest) request;
      HttpServletResponse httpServletResponse = (HttpServletResponse) response;
      Cookie[] cookies = httpServletRequest.getCookies();
      for (Cookie c : cookies) {
          if (c.getName().equals("lang")) {
              httpServletResponse.sendRedirect("home.xhtml");
          }
      }
      chain.doFilter(request, response);
  </code></pre>
  
  <p>But I still got the Response already committed exception...</p>
  
  <p>Can anyone help me ?</p>
  
  <p>Thanks</p>
  
  <p>Stephane </p>