serenskye
serenskye

Reputation: 3467

Accessing Flash from template in Java

I'm very new to using the play framework and Scala.

My app is written using Play Framework 2.3 in Java and I'm setting a Flash in my controller. However when I redirect to my view the Flash is always unavailable.

Just before I redirect, I've logged whether the Flash is set, and this logs true.

public static Result upload() {
    flash("error", "test flash");
    System.out.println("flash " + flash().containsKey("error"));
    return redirect(routes.Application.upload());
}

in my template:

<p>flash: @flash.get("error")</p>

Upvotes: 2

Views: 847

Answers (1)

Yann Simon
Yann Simon

Reputation: 458

See https://www.playframework.com/documentation/2.3.x/JavaSessionFlash

Data in the Flash scope are kept for only one request. I guess you have to read the data and put it in the flash once more:

String error = flash("error");
flash("error", error);
return redirect(routes.Application.upload());

Upvotes: 1

Related Questions