scala - "could not find implicit ... flash" in invoking nested view template -
scala - "could not find implicit ... flash" in invoking nested view template -
note problem described in "flash not found in products.scala" not same, , has been addressed.
the chapter 2 walkthrough in "play scala" book includes "editproduct.scala.html" reads:
@(productform: form[product]) (implicit flash:flash, lang:lang) @import helper.twitterbootstrap._ @main(messages("products.form")){ ... } }
the play 2.3.8 compiler errors out with:
error:(4, 33) play 2 compiler: .../editproduct.scala.html:4: not find implicit value parameter flash: play.api.mvc.flash @main(messages("products.form")){ ^
i interpret mean reason, "flash" on first line not satisfactory invoking "main" template on line 4. "main" template begins with:
@(title: string)(content: html)(implicit flash: flash, lang: lang)
i don't think it's relevant, controller code invoking form reads:
import play.api.mvc._ import models.product import play.api.data.form import play.api.data.forms.{mapping,longnumber,nonemptytext} import play.api.i18n.messages object products extends controller { ... def newproduct = action { implicit request => val form = if (request.flash.get("error").isdefined) productform.bind(request.flash.data) else productform ok(views.html.products.editproduct(form)) } ... }
can suggest try? book based on play framework 2.1, , i'm using 2.3.8, might kind of version-dependency - can't find on or in docs supports theory.
[answering own post.] cause of problem seems of implicit values, such "flash", available implicitly top-level templates, because supplied implicit converters in controller @ point of invocation. since templates don't inherit controller, when phone call nested templates these converters out of scope.
the solution explicitly pass in that's missing (like "flash") nested templates need it. "main" template begins:
@(title: string, flash:flash)(content: html)(implicit lang:lang)
i don't know why "lang" works implicitly. note play-compiler error, not scala-compiler error; may clue.
scala playframework-2.0
Comments
Post a Comment