Reputation: 3319
Im trying to pass flash content to a view and it doesnt show up.
Ok( views.html.myView(parameter1,parameter2) ).flashing("success" -> "hallo")
In the template i try to use it like this:
@(parameter1: String, parameter2: String)(implicit flash: Flash)
@flash.get("success").map { message =>
<p class="success">
@message
</p>
}
Problem is, the flash scope never reaches the view. I have no output on screen. When i debug it, i see that the flash map is empty.
How can i call myView in a way that the flash scope can be processed?
Upvotes: 1
Views: 2283
Reputation: 23093
There is no reason to flash if the response is a 200. Just pass a Map to your view. (You can't pass a Map on a Redirect, so it makes sense that'd you'd want to use a flash there.)
Upvotes: 0
Reputation: 26
I had struggled with this issue as well. Finally found a decent solution.
The critical point is flash being an implicit parameter in the view. That means it needs to be taken by Redirect where the Flashing is "packed" along with the result.
Solution: Create a new Flash object right away
Ok( views.html.myView(parameter1,parameter2) (Flash(Map("success" -> "hallo"))) )
The view stands unchanged.
Inspired by "[2.0.2-scala] Is flashing only intended for redirects?" discussion
Upvotes: 1
Reputation: 2468
I guess flashing only works with Redirect, so use Redirect or just pass the parameters with success information strait to the view
Upvotes: 0