Frage

Suppose a scala play view is supposed to render a range of items if available. If not we want to have a message output instead. It has been suggested to me to get the message from controller to view via "flashmessage" instead of a parameter of the view.

Is using flashmessage the appropriate way to get text from controller to view?

Iam having doubts because flashmessage is primarily used to get data across redirects. Also its subject to race conditions if another page is loaded at the same time and values are overwritten.

War es hilfreich?

Lösung

You are right. A flash message is not supposed to get data from the controller to view.

Suppose you have the following code:

Ok(something.render()).flashing("myitem" -> "item1")

And your view has something like this:

flash.get("myitem").getOrElse("")

You will get an empty value. Instead you would be forced to use Redirects, so I think this is a bad idea

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top