Lang和requestLang中的模棱两可的值

Lang和requestLang中的模棱两可的值

本文介绍了Lang和requestLang中的模棱两可的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用:PlayFramework 2.3和SecureSocial(与2.3兼容的版本)

Using: PlayFramework 2.3 and SecureSocial (compatible version with 2.3)

我在ViewTemplate中收到此错误:

Im receiving this error in the ViewTemplate:

[error] /Users/einevea/projects/einjar/einevault/econcepts/modules/eusers/app/services.eusers/MyViewTemplates.scala:29: ambiguous implicit values:
[error]  both method request2lang in trait Controller of type (implicit request: play.api.mvc.RequestHeader)play.api.i18n.Lang
[error]  and value lang of type play.api.i18n.Lang
[error]  match expected type play.api.i18n.Lang
[error]   override def getStartSignUpPage(form: Form[String])(implicit request: RequestHeader, lang: Lang): Html = views.html.eusers.custom.startSignUp(WUPage(Messages("securesocial.signup.title")),form)(request, lang, env)

有帮助吗?

推荐答案

错误消息表示您已尝试调用getStartSignUpPage,并且需要一个隐式play.api.i18n.Lang,但是您的作用域中有两个隐式Lang实例,因此编译器不知道该选择哪一个.

The error message means that you have tried to call getStartSignUpPage and that takes an implicit play.api.i18n.Lang but there are two implicit Lang instances in your scope, so therefore the compiler does not know which one to choose.

第一个是您已导入或定义的值lang(作为模板中的值或模板的参数列表中的隐式参数)

The first one is the value lang which you have imported or defined (either as a value in the template or as an implicit parameter in the parameter lists of the template)

第二个是内置的,来自播放Controller.request2Lang,它知道如何从请求中提取Lang来选择浏览器表示接受的语言(在Accept-Language标头中).

The second one is a built in one that comes from play Controller.request2Lang which knows how to extract Lang from the request to select the language that the browser said that it accepts (in the Accept-Language header).

您可以通过以下几种方法解决此问题:避免在作用域中有两个Lang实例,在调用getStartSignUpPage的位置显式提供参数,或将隐式参数列表设置为常规参数列表.

You could work around this in a few ways: avoid having two Lang instances in scope, provide the parameters explicitly where you call getStartSignUpPage or make the implicit parameter list a regular parameter list.

这篇关于Lang和requestLang中的模棱两可的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 10:23