1
votes

I'm new to scala and play.

I want call a controller func from view but I don't want to return Result type. What I want to do is modify the Request.session value.

The approach I did was : 1) case

1) case

controller :

def func(id : Int)(implicit request: RequestHeader) = { ... } 

routes :

GET    /cart/cancel/:id    controllers.ProductController.func(id:Int)

But it gave me a compilation error : Cannot find any HTTP Request Header here

So I did the another approach 2) case

2) case

controller :

def func(id : Int) = Action { implicit request => ... Ok()}

Yes. It worked. But this time I have Result type returned. So I'm obligated to change the state of page anyway

Is there any way to deal with session value without Action function (without state transition) ?

Thank you!

1

1 Answers

0
votes

You can use case 2 and do something like:

Ok().withSession(
  session - "id" + ("id" -> "newID")
)

You can then call your controller via Ajax for instance, the change to your session will then be taken into account, you can then apply the changes to UI (if any) once you get the Ok status back from your controller. If there are no apparent changes, then you can stop there, all the following interactions with the app will be using this new session.