Questions with Flashscope

Asked

Viewed 488 times

2

Hello, all 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 goes down and so on, the view stays as long as we don’t redirect, but what about the Flash? We need to remove the attribute ?

In this blog (link) the author makes the following quotation:

"The Flash scope does nothing more than guard the object as if it were a session. Note the fact 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 someone enlighten me a little?

EDIT:

I ended up trying to venture and I got good results, only there’s something that annoys me that are the messages of WARNING that the JSF sends:

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.

There’s a way to disable it?

EDIT2: Here’s the code I’m using:

This is my method that I inserted and takes from the 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);
}

This is where I place an object in the Scope flash and redirect it:

    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");
}
  • I think this one question can help understand the behavior of Flashscope. At least in the implementation of the Mojarra project, Flashscope is managed via Cookies by Elflash, made to maintain a scope in req. of type Post-redirect-Get. If you observe a req. Where the Flash was used, you will see a cookie called "csfcfc" which is roughly a key of a Map that maintains the Flash scope. The problem is a cookie is being created after req. is "commited", if you can identify the code that generates the Warning, could include it in the question?

  • Hi Wakim, thank you for your attention, I added some codes that I use to manipulate the flash

  • Managed to resolve your question @Paulogustavo ? if yes, post as answer to help other users.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.