How can I get rid of these warning? Do I really have to send a “Http.Request” object from each of my controllers to my templates?
Thanks,
[EDIT] By the way, following the link in the warning redirects me here: playframework .com/documentation/fr/2.4.x/JavaHttpContextMigration27 (limited to two links per messages) which is a 404
Basically for those warnings you need to do one of the 2 things.
Pass an instance of Http.Request direct into the template.
For PlayMagicForJava, you need to pass things like Request or Messages as an implicit parameter like this @(names: List[String])(implicit request: Http.Request), and in Java land, the request parameter in this case will just be another parameter you’ll need to pass in. The warnings should just go away if you do that.
So what you say is that I have to send a request parameter to my template if I am using play java?
It’s quite annoying. in coding style it’s more a regression than otherwise…
But if there is no other solution, I’ll do it this way
For PlayMagicForJava, there’s simply no other solution, since implicit parameters don’t exist in Java. But if you want to access request data yourself, you can always create your own ThreadLocal<Http.Request> and use that.
This is a way to make things more readable and explicit to developers. If your template needs to access the request for some reason, then it makes sense that you pass the gets it as a parameter. I think that we will eventually provide ways to pass the information the view need (in this case the CSRF token) directly, but overall, the idea is to remove some of the APIs that were too hidden and then too surprising when things didn’t work as expected.
Two things we can do to help here is to pinpoint better where at the migration you should look for that specific warning. The other one is to make it more explicit at the CSRF docs that you now need to pass an Http.Request. Do you have time to submit a PR to address these issues?
Hum, that is odd. Here is the (compiled and tested) example that we have in our docs:
As you can see there, there is no need to call asScala, and that is because Play provides an implicit conversion between Http.Request and play.api.mvc.Request:
And this should be imported by default in your templates:
If this is not happening, could you create a small project that reproduces the problem?