I am currently struggling to find a way to implement alerts in a reusable and clean fashion. I am not sure if Play's flashing is only intended for redirects, but this post indicates that there's a workaround for flashing with instances of class Result
.
The workaround suggests to use an implicit
parameter for the view, for example:
@(clientForm: Form[models.Client])(implicit flash: Flash)
And then simply do something like this:
val flash = play.api.mvc.Flash(Map("error" -> "Please select another id for this client"))
Ok(views.html.clients.new_client(boundForm)(flash))
The problem is that I do have multiple implicit parameters in my view, i.d.:
(implicit request: RequestHeader, messages: Messages, flash: Flash)
So the compiler complains with:
Unspecified value parameters: flash: Flash, messages: Messages
How can I solve this?
Making flash
implicit, as suggested in the (deleted) answer, didn't solve the problem. I still get this compile error:
ambiguous implicit values: both method request2flash in trait Controller of type (implicit request: play.api.mvc.RequestHeader)play.api.mvc.Flash and value flash of type play.api.mvc.Flash match expected type play.api.mvc.Flash
import play.api.i18n.Messages.Implicits._
– Samarflash
implicit and not passing it to the view, I still get this compile error. I don't think that it has something to do withMessages
, since everything worked before introducingFlash
. Do you have any other suggestions how alerts can be implemented in a reusable way? – John Doeimplicit val flash = play.api.mvc.Flash(Map("error" -> "Please select another id for this client"))
– Samar