Hello, is everything good? I have a question regarding the use of flashScope and would like your help.
When we put an attribute inside FlashScope, how long does it stay there? I mean, the attributes of the session stay until the session falls and etc, the view stays while we do no redirect, but what about Flash? Do we need to remove the attribute?
In this blog (link) the author makes the following quote:
"The Flash scope does nothing more than save the object as if it were a session. Note that after its use the" user "object will be removed from the scope."
So when I do put an attribute and then do a get on it, it will automatically be destroyed?
Can anyone clarify me a little?
EDIT:
I just tried to venture out and got good results, but there's something that's pissing me off about the WARNING
Apr 24, 2015 5:31:10 PM 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.
Can you disable this?
EDIT2: Here is the code I am using:
This is my method that I inserted and took from flashScope:
public static Object getFlashAttribute(String attributeName) {
return getExternalContext().getFlash().get(attributeName);
}
public static void setFlashAttribute(String key, Object value) {
getExternalContext().getFlash().put(key, value);
}
Here is where I put an object in the flash scope and do the redirect:
public String openPostConf() {
if (selectedFeeds.size() != 1) {
strFeedMessage = "";
return "";
}
Feed feedEdition = selectedFeeds.get(0);
LOGGER.info("Editando conteudo: " + feedEdition);
JSFHelper.setFlashAttribute("feedToEdit", feedEdition);
markAll = false;
return "toEditFeed";
}
And here is where I get, in the builder of my other managedBean:
public PostConfMB() {
feedForEdition = (Feed) JSFHelper.getFlashAttribute("feedToEdit");
}