找不到参数Flash的隐式值 [英] Could not find implicit value for parameter flash
问题描述
我正在尝试将一些代码从Play Framework Java移植到Play Framework Scala,但是在移植标签方面遇到一些问题.
I'm trying to port some code from Play Framework Java to Play Framework Scala but I'm having some issues with porting a tag.
Java版本中存在问题的标记检查Flash范围的内容,并根据其值(错误,成功等)向用户创建通知.
The tag in question in the Java version checks the contents of the Flash scope and creates notifications to the user according to its values (error, success, etc).
我试图创建一个Scala视图(flag.scala.html
):
I tried to create a Scala view (flag.scala.html
):
@()(implicit flash:play.mvc.Scope.Flash)
@if(flash.get("error")) {
<p style="color:#c00">
@flash.get("error")
</p>
}
我从main.scala.html
通过以下方式致电
@views.Application.html.flag()
我得到的错误是:
文件{module:.}/tmp/generation/views.html.main.scala不能为 编译.引发的错误是:找不到以下内容的隐式值 参数flash:play.mvc.Scope.Flash
The file {module:.}/tmp/generated/views.html.main.scala could not be compiled. Error raised is : could not find implicit value for parameter flash: play.mvc.Scope.Flash
对新标签的调用是正确的,就像我用浏览器中显示的某些String替换内容一样.
The call to the new tag is correct, as if I replace the content by some String that's shown in the browser.
我确定这很愚蠢,但是我被卡住了.有什么建议吗?
I'm sure it's something stupid but I got stuck. Any suggestion?
推荐答案
我不知道Play的详细信息,但是此编译错误表明您应该:
I don't know the details of Play, but this compile error is saying you should either:
-
在对
flag()
的调用中将play.mvc.Scope.Flash
的显式实例传递给
Pass an explicit instance of
play.mvc.Scope.Flash
in the call toflag()
,
views.Application.html.flag()(myFlash)
或
在调用flag()
的范围内使Flash
的隐式实例可用.您可以通过导入某些对象(import some.path.FlashImplicits._
)的内容或自己定义隐式实例来实现此目的,
Make an implicit instance of Flash
available in the scope where flag()
is called. You could do this by importing the contents of some object (import some.path.FlashImplicits._
) or by defining the implicit instance yourself,
implicit val myFlash: play.mvc.Scope.Flash = ...
...
views.Application.html.flag()
因此,真正的问题变成了:您想从哪里获得该Flash
实例?
So the real question becomes: where do you want to get this Flash
instance from?
这篇关于找不到参数Flash的隐式值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!