Reputation: 11
I'm trying to get the flash data that has been passed from the controller in the view. In the Play documentation (https://www.playframework.com/documentation/2.8.x/JavaSessionFlash) it says the flash can be get like this:
@flash.get("success").orElse("Welcome!")
However, I'm getting this error when I try to compile the project
[error] .../edit.scala.html:4:3: not found: value flash
[error] @flash.get("test").orElse("No flash!")
[error] ^
[error] one error found
[error] (Compile / compileIncremental) Compilation failed
I've also tried using @request.flash
and it gave the same error.
How can I get the flash or request in the view for Play Framework 2.8. Am I missing some import or something like that?
Upvotes: 1
Views: 1229
Reputation: 6499
Since you're using Java you need to pass the request param to the template. At the top of the template file:
@( ... your normal params ...)(implicit request: Http.Request)
Now to get the flash use the request:
@request.flash().getOptional("test")
Upvotes: 1