Confused about flash-scope

228 views
Skip to first unread message

GrailsDeveloper

unread,
May 28, 2012, 5:13:59 AM5/28/12
to play-fr...@googlegroups.com
Hi I try to store some data in a flash-scope. The use case is that I need some data for the next request. So

   public static Result login() {
        flash().put("xxx","yyy");
        return ok(login.render(loginForm));
    }

    public static Result signIn() {
        System.out.println(flash().get("xxx"));
    }

The LoginForm call signIn. How ever the flash is empty? Have I a wrong understanding of flash or what's wrong?

Niels

biesior

unread,
May 28, 2012, 6:36:34 AM5/28/12
to play-fr...@googlegroups.com
ellou' Niels

Flash scope is available only for ONE request and this is inyour case login.render()

If you need to pass it trought more requests you need to do it by passing as params, or with session scope (which is similar to the flash scope, but isn't deleted automatically, so you need to delete session key manually after use).

greetings biesior

GrailsDeveloper

unread,
May 28, 2012, 1:15:03 PM5/28/12
to play-fr...@googlegroups.com
Thanks for clarification. I thought it would be put into a cookie too. So as you described it is a change to play1.x and grails. What I don't understand is, where is the different to the request-scope? I changed my code to session-usage now
Niels

James Roper

unread,
Sep 28, 2012, 9:27:11 AM9/28/12
to play-fr...@googlegroups.com
Sorry for resurrecting an old post, but I thought I should clarify in case someone comes across this post.  Niels, you are right, it is intended to work just as in Play 1, the flash scope is available for the next request.

The problem here is most likely that your login page is making a call to download some assets or something like that, so the next request is not the sign in request, its a request to download an image, js, css, whatever.  This request causes the flash scope to be cleared.

Flash scope is intended primarily to be used in situations when you are 99.9999% sure that the next request will be the request it's intended for.  This basically only applies to redirects.
Reply all
Reply to author
Forward
0 new messages