I get an IllegalStateException
when redirecting from a preRenderView
event. I have worked around it by just ingoring the exception. Is there a cleaner way to achieve the same result?
@Named
@RequestScoped
public class LogoutBean implements Serializable
{
public void preRenderView(ComponentSystemEvent e)
{
userSessionBean.logout();
FacesContext ctx = FacesContext.getCurrentInstance();
try
{
ctx.getApplication().getNavigationHandler().handleNavigation(ctx, null, "/pages/index?faces-redirect=true");
}
catch (IllegalStateException exc)
{
// Ignore. This exception is caused by redirecting after the response is already committed. The redirect works anyway.
}
}
@Inject
private UserSessionBean userSessionBean;
}