找不到参数Flash的隐式值 [英] Could not find implicit value for parameter flash

查看:73
本文介绍了找不到参数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:

  1. 在对flag()的调用中将play.mvc.Scope.Flash的显式实例传递给

  1. Pass an explicit instance of play.mvc.Scope.Flash in the call to flag(),

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆