5
votes

I run Play Framework 2.2.1. I used to have only java controllers rendering templates. Now I am adding a Scala controller to render a new template indexScala.scala.html. The parameters list for indexScala.scala.html:

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

and it calls

@mainEmptyScala("blah", head) {}

The parameters list for mainEmptyScala.scala.html:

@(title: String, head: Html = Html(""))(body: Html)(implicit request: play.api.mvc.RequestHeader)

When I call indexScala template, I also declare request as implicit in the Scala controller. However, I got this compile error.

[error] ~/myapp/app/views/indexScala.scala.html:29: ambiguous implicit values:
[error]  both method requestHeader in object PlayMagicForJava of type => play.api.mvc.RequestHeader
[error]  and value request of type play.api.mvc.RequestHeader
[error]  match expected type play.api.mvc.RequestHeader
[error] @mainEmptyScala("blah", head) {
[error]                               ^

I made sure that indexScala and mainEmptyScala templates are not called by any Java controller, so PlayMagicForJava shouldn't be used. Does anybody know how to resolve this compile error? Thanks.

2
Do you have solved that problem? I've the same situation on my project.endrigoantonini
No, I use a workaround. I pass the RequestHeader explicitly.coolsuntraveler

2 Answers

1
votes

After having the same problem i stumbled upon a solution. The solution that works for me that i am on Play Framework 2.3.x with Scala 2.11.1.

Just use play.api.mvc.Request everywhere in your templates:

@()(implicit request: play.api.mvc.Request[Any])
0
votes

In your controller, I am assuming that you have something like this:

def myAction() = Action { implicit request =>
    Ok(someView())
}

So by default, if you dont specify the implicit in your view paramters i.e.

Change

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

To

@()

You should still be able to access the RequestHeader in your view explicitly. So then you would then need to call:

@mainEmptyScala("blah", head) {}(request)

I haven't tested this, but I this should work