Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting warning from JSF: The response was already committed by the time we tried to set the outgoing cookie for the flash

I have a page1.jsf, in this page i have a commandButton that put an object in ELFlash, and redirects to page2.jsf. In this page i recover the object by ELFlash. Everything works fine. But while the user remains in page2.jsf, for every ajax request, tomcat shows this warning message:

20/07/2013 09:43:37 com.sun.faces.context.flash.ELFlash setCookie
WARNING: JSF1095: The response was already committed by the time we tried to set the outgoing cookie for the flash.  Any values stored to the flash will not be available on the next request.

What does it really mean?

like image 770
Mateus Viccari Avatar asked Jul 20 '13 12:07

Mateus Viccari


2 Answers

Instead of using a Filter as mentioned in @Rafal K answer, you can also increase the response buffer size by setting a context parameter in your web.xml

<!-- increase buffer size to avoid JSF1095 errors -->
<context-param>
    <param-name>javax.faces.FACELETS_BUFFER_SIZE</param-name>
    <param-value>131072</param-value>
</context-param>

The size is given in bytes and should be larger than your biggest page. You can easily check the size of your pages in Firefox by right clicking and selecting View Page Info.

like image 126
jansohn Avatar answered Sep 19 '22 22:09

jansohn


I think that problem might be related to http chunking. Solution is to increase response buffer size. After that cookies will be set correctly and Flash Scope should work too.

Use this code:

public class FlashScopeFixerFilter implements Filter {
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    // Below line: response.getWriter() must be invoked to buffer size setting work. Just DO NOT touch this!
    response.getWriter();
    HttpServletResponseWrapper wrapper = new HttpServletResponseWrapper((HttpServletResponse) response);
    wrapper.setBufferSize(10000000);
    chain.doFilter(request, wrapper);
}

@Override
public void init(FilterConfig arg0) throws ServletException {}
@Override
public void destroy() {}
}

And in web.xml:

<filter>
    <filter-name>FlashScopeFixerFilter</filter-name>
    <filter-class>dk.sd.medarbejderdata.common.FlashScopeFixerFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>FlashScopeFixerFilter</filter-name>
    <url-pattern>*.xhtml</url-pattern>
</filter-mapping>
like image 25
Rafal K Avatar answered Sep 19 '22 22:09

Rafal K