I have been struggeling with the Flash-scope (I know it is not a "scope" like the others, but often referred to as one) in JSF 2.0. (Mojarra)
My problem is that the flash-cookie is bound to the path of the view putting the object in flash.
This resulting in objects not being available after redirect to a different path in the same application.
We need to have Strings (and probably objects) available on the other side of the redirect-navigation.
I have implemented a @WebFilter
which purpose is to override this and replace the ServletResponse
with the following wrapper.
private class ResponseWrapper extends HttpServletResponseWrapper{
private final String path;
public ResponseWrapper(HttpServletResponse response, String contextpath) {
super(response);
this.path = contextpath;
}
@Override
public void addCookie(Cookie cookie) {
// Hardcoded name from jsf-impl # com.sun.faces.context.flash.ELFlash
final String FLASH_COOKIE_NAME = "csfcfc";
if (cookie.getName().equals(FLASH_COOKIE_NAME)){
cookie.setPath(path);
}
super.addCookie(cookie);
}
}
In effect this wrapper will modify the flash-cookies to be bound to the applications context-root.
My question is whether this will cause other problems that I do not oversee.
I am not able to understand why the Flash
should be bound to the path of the view in the first place.