Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Play 2.2.1: ambiguous implicit values for object PlayMagicForJava

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.

like image 203
coolsuntraveler Avatar asked Nov 10 '22 11:11

coolsuntraveler


1 Answers

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])
like image 100
R Gastmeier Avatar answered Nov 14 '22 22:11

R Gastmeier