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

最后都变了- 提交于 2019-11-28 06:30:28

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.

Rafal K

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>

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!