1

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

Community
  • 1
  • 1
Stéphane
  • 514
  • 5
  • 16
  • I wouldn't expect the response to be already committed at that point. Might be a WebLogic specific quirk. Have you considered a simple servlet filter? It should guaranteed work and is also more "the right tool for the job" in this particular case. – BalusC Feb 15 '13 at 12:50
  • As to your filter attempt, you're still continuing the request after sending the redirect. Add a `return` statement right after the `sendRedirect()` line. – BalusC Feb 15 '13 at 13:56

0 Answers0