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.
@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";
}
}
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:
java.lang.IllegalStateException: Cannot create a session after the response has been committed
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.
I'm using MyFaces 2.1.