title: Redirect after logout fails with java.lang.IllegalStateException: Cannot create a session after the response has been committed
body: <p>I have a JSF2 application. I have a login bean which is session scoped and a logout bean which is view scoped. When I login I use redirect and it works fine. However the logout fails with redirect. If I logout without redirect it works.</p>
  
  <pre><code>@ManagedBean
  @ViewScoped
  public class MbLogout extends BaseJsf {
      private static final long serialVersionUID = 2992671241358926373L;
  
      public String logout() throws DfException {
          getFacesContext().getExternalContext().invalidateSession();
  
          //return "login?faces-redirect=true"; // fails with this
          return "login";
      }
  }
  </code></pre>
  
  <p>The login page has bindings to the login bean so I suspect this may have something to do with it, although I don't see why it doesn't work. The error is:</p>
  
  <pre><code>java.lang.IllegalStateException: Cannot create a session after the response has been committed
  </code></pre>
  
  <p>My guess is it's trying to create a session on the login page since I access the session bean although I don't see anything wrong with this and it works without redirect.</p>
  
  <p>I'm using MyFaces 2.1.</p>