18

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?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Mateus Viccari
  • 7,389
  • 14
  • 65
  • 101
  • 2
    It really means that Flash is still broken in Mojarra. Which Mojarra version are you using? – BalusC Jul 20 '13 at 16:10
  • Could it be related with [this](http://stackoverflow.com/questions/17668986/exception-about-flash-with-jsf-2-2-1)? – Aritz Jul 21 '13 at 12:46
  • Could be [JSF-2896](https://java.net/jira/browse/JAVASERVERFACES-2896). I'm still seeing this with Mojarra-2.2.5, using Post-Redirect-Get and Omnifaces' `addFlash()` in a complex page. – mabi Jan 22 '14 at 14:32

4 Answers4

13

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.

jansohn
  • 2,246
  • 2
  • 28
  • 40
4

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>
Dani
  • 3,744
  • 4
  • 27
  • 35
Rafal K
  • 41
  • 2
  • that's currently the only thing that works for us. our logs were still full with this annoying warning in mojarra 2.2.14 – Steve Jul 06 '17 at 08:03
2

This warning may be caused if you're using Flash for ajax requests. Probably you're trying to do a redirect with ajax set to true and in the listener you're putting values into Flash. Verify if ajax is needed and set it to false for redirections.

Just don't mix ajax=true on commandButtons with flash and you'll be free of this warning.

Michał Stochmal
  • 5,895
  • 4
  • 36
  • 44
-1

Flash as it should suggest the name is meant to be a sort of temporary container concept between the life cycle of jsf. The point is the following: the object stored in the flash will be promoed to the user in the very next view he will encounter(remember that jsf follows the mvc), thus after being 'used' it will disappear, namely will be removed.

I think that's why you get such error, and that is not related directly with mojarra.

LMG
  • 966
  • 1
  • 12
  • 28
  • You're not answering the concrete question at all. Ideally, those warning messages should not be shown at all. Nothing in your answer offers a solution to that. – BalusC Aug 18 '13 at 21:37
  • What about 'Any values stored to the flash will not be available on the next request.'?? :o – LMG Aug 18 '13 at 21:58
  • This is just the warning message, and it just tells me the expected behavior, which means there was no reason to be shown in a warning, and my question was, why this is happening. – Mateus Viccari Aug 19 '13 at 13:20
  • I have literally misunderstood then! – LMG Aug 21 '13 at 11:14