Skip to content

Passing messages to view in Play!

peterszatmary edited this page Feb 20, 2016 · 1 revision

Passing messages to views

if you stay in page use view parameter

return badRequest(views.html.registration.render(Messages.get("registration.not.sucessfull"), form));
@(message : String, registrationForm: Form[core.pl.formdata.RegistrationData])

...

@if(message != null || message != "") {
   <p class="notValidText">@message</p>
}

if you redirect use flash scope messages

flash("registrationSuccess", Messages.get("registration.sucessfull"));
return redirect(routes.Application.index());
<p class="notValidText">@message</p>
@if(flash.containsKey("registrationSuccess")) {
   <p class="validText">
     @flash.get("registrationSuccess")
   </p>
}

if you need more durational messages use session scope. Same like flash just use scope instead keyword scope.