I have the following play2 code:
implicit def contextToRequest(rc: RequestContext[_]) = rc.request
implicit def contextToFlash(rc: RequestContext[_]) = rc.request.flash
implicit def contextToSession(rc: RequestContext[_]) = rc.request.session
def login: Action[AnyContent] = PublicAction { implicit rc =>
Ok(html.login(loginForm))
}
RequestContext is my own custom class wrapper of the Play2 Request.
My scala view starts with:
@(form: Form[(String,String,Boolean)])(implicit flash: Flash, session: Session,rc: utils.RequestContext[_])
But the compiler says:
could not find implicit value for parameter flash: play.api.mvc.Flash
Can someone explain to me why it doesn’t work?
Perhaps we can’t use implicit conversions for implicit parameters?
Then can someone explain to me why there is already a working implicit conversion from the Play2 request to Session/Flash and when I do it it doesn’t work?
When you end up having multiple implicit parameters, some of which are members properties of the others, there is something wrong in your design.
In fact, what you want to have inside your method are the B and the C members of that A. However, with such a signature one can provide a given A and a B and a C which have nothing to do with that A. The right signature would be the following