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).
So I've set a listener :
<f:event listener="#{languageSelectionController.checkSkipLanguageSelection}" type="preRenderView" />
that check if the cookie is present and if so redirect to the home page (without propose language choice page)
if (languageBean.isValidCookieDetected()) {
FacesContext.getCurrentInstance().getApplication().getNavigationHandler().handleNavigation(FacesContext.getCurrentInstance(), "languageSelection.xhtml", "toHome");
}
But I get an exception
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)
I've read the post What exactly does "Response already committed" mean? How to handle exceptions then? and try to raise the buffer size but it changes nothing.
UDPATE :
I've set a filter with the following 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);
But I still got the Response already committed exception...
Can anyone help me ?
Thanks
Stephane