user3789309
user3789309

Reputation: 31

flash/session not found after migration to 2.3

I have such error in scala template:

not found: value flash

19        @if(flash.contains("bladLogowania")) { 
20        <p class="error">
21        @flash.get("bladLogowania")
22       </p>}

I have read that there is some change but I am not sure how make this work. I still want check this values from template directly. Any ideas?

Upvotes: 2

Views: 1241

Answers (4)

Casey Murray
Casey Murray

Reputation: 1582

Changes I made to compile after 2.3 migration where using implicit flash becomes an issue:

To my Controller class:

add import play.api.mvc.RequestHeader;

change flash("success", "Logged Out");

to request.flash("success", "Logged Out");

To my scala.html classes using the implicit flash:

add (implicit request: play.api.mvc.RequestHeader)

change

@if(flash.contains("success")) {
                <p class="success">
                    @flash.get("success")
                </p>
            }

to

@if(request.flash.data.contains("success")) {
                <p class="success">
                    @request.flash.get("success")
                </p>
            }

Note the need to access the map using flash.data. Hope it helps!

Upvotes: 1

I face the same kind of errors when code for Play 2.3.X. I found that documentation about migration to 2.3.X is wrong. Digging the Play api doc I found that you just have to add a import to Http.context.Implicit to acess flash scope like you did before play 2.3.X:

@import play.mvc.Http.Context.Implicit

Upvotes: 0

Peter Morris
Peter Morris

Reputation: 23254

Change your controller code to request.flash instead of just flash

Upvotes: 2

Donovan Muller
Donovan Muller

Reputation: 3842

Please read the migration guide to 2.3: http://www.playframework.com/documentation/2.3.x/Migration23, specifically the "Session and Flash implicits" section

So your code would change to:

@if(request2flash.contains("bladLogowania")) { 
  <p class="error">
    @request2flash.get("bladLogowania")
  </p>
}

Upvotes: 0

Related Questions