我正在尝试使用play 2
自定义模块“securesocial”提出的视图我已经做的是:
1 /创建一个新的插件名称SecureViewsPlugin,实现“controllers / SecuresViewsPlugin.scala”下的TemplatesPlugin
package controllers
import play.api.mvc.{RequestHeader, Request}
import play.api.templates.Html
import securesocial.controllers.Registration.RegistrationInfo
import securesocial.controllers.TemplatesPlugin
import securesocial.core.{SecuredRequest, SocialUser}
import play.api.data.Form
import securesocial.core.SecureSocial._
import securesocial.controllers.PasswordChange.ChangeInfo
class SecureViewsPlugin(application: App) extends TemplatesPlugin {
override def getLoginPage[A](implicit request: Request[A], form: Form[(String, String)],
msg: Option[String] = None): Html =
{
views.html.secure.login(form, msg)
}
override def getSignUpPage[A](implicit request: Request[A], form: Form[RegistrationInfo], token: String): Html = {
views.html.secure.Registration.signUp(form, token)
}
(..)
2 /我用以下文件更新了play.plugins文件:
1500:com.typesafe.plugin.CommonsMailerPlugin
9996:securesocial.core.providers.utils.DefaultPasswordValidator
9997:controllers.SecureViewsPlugin
3 /我复制了“views / secure”文件夹中的不同视图
/Views
/secure
/inputFieldConstructor.scala.html
/login.scala.html
/(...)
这是我总是得到的错误的开始
not found: type RequestHeader
In app/views/secure/login.scala.html at line 0.
->@(loginForm: Form[(String,String)], errorMsg: Option[String] = None)(implicit request: RequestHeader)
[error] /Users/clementaubert/Desktop/demo/target/scala-2.9.1/src_managed/main/views/html/secure/login.template.scala:24: not found: type RequestHeader
[error] object login extends BaseScalaTemplate[play.api.templates.Html,Format[play.api.templates.Html]](play.api.templates.HtmlFormat) with play.api.templates.Template3[Form[scala.Tuple2[String, String]],Option[String],RequestHeader,play.api.templates.Html] {
[error] ^
[error] /Users/clementaubert/Desktop/demo/target/scala-2.9.1/src_managed/main/views/html/secure/login.template.scala:27: not found: type RequestHeader
[error] def apply/*1.2*/(loginForm: Form[(String,String)], errorMsg: Option[String] = None)(implicit request: RequestHeader):play.api.templates.Html = {
[error] ^
[error] /Users/clementaubert/Desktop/demo/app/controllers/SecureViewsPlugin.scala:18: type mismatch;
[error] found : play.api.data.Form[(String, String)]
[error] required: play.data.Form[(java.lang.String, java.lang.String)]
[error] views.html.secure.login(form, msg)
[error]
login.scala.html
我试图删除“(隐式请求:RequestHeader)”,但后来我收到了这个错误
type mismatch; found : play.api.data.Form[(String, String)] required: play.data.Form[(java.lang.String, java.lang.String)]
我猜我没有以正确的方式做到这一点。
我无法弄清楚为什么我会收到这些错误
答案 0 :(得分:3)
我有同样的问题,或者非常相似。看看这是否可以帮到你:
错误:强>
[error] C:\workspace\zenplanning\app\views\index.scala.html:0: not found: type RequestHeader
[error] C:\workspace\zenplanning\app\views\index.scala.html:1: not found: type RequestHeader
[error] @(loginForm: play.api.data.Form[(String,String)], errorMsg: Option[String] = None)(implicit request: RequestHead
er)
[error] ^
play.PlayExceptions$CompilationException: Compilation error[not found: type RequestHeader]
<强>原因:强>
我认为这是因为securesocial在您的路由器上使用scala而我在Play项目中使用Java。发送的RequestHeader在Scala(play.api.mvc.RequestHeader)中,但我的模板在Java中期待(play.mvc.RequestHeader)。
<强>解决方案强>
要解决此问题,我在自定义login.scala.html中修改了:
@(loginForm: play.api.data.Form[(String,String)], errorMsg: Option[String] = None)(implicit request: RequestHeader)
对此:
@(loginForm: play.api.data.Form[(String,String)], errorMsg: Option[String] = None)(implicit request: play.api.mvc.RequestHeader)
答案 1 :(得分:2)
您必须执行以下操作:
在所有Views / secure /...*。scala.html文件中:
用play.api.mvc.RequestHeader替换:RequestHeader 使用play.api.data.Form
表单[String,String]或Form [String]例如在startSignUp.scala.html文件中,更改原始文件:
@(startForm:Form [String])(隐式请求:RequestHeader)
与
@(startForm:play.api.data.Form [String])(隐式请求:play.api.mvc.RequestHeader)
答案 2 :(得分:0)
阿巴斯提到了让你自己的模板工作的第一步。
但对我而言仍然没有成功。引发了这个异常:
play.api.PlayException: Cannot load plugin [Plugin [controllers.MyTemplatePlugin] cannot been instantiated.]
...
Caused by: java.lang.NoSuchMethodException: controllers.MyTemplatePlugin.<init>(play.Application)
解决此问题的方法是从
调整模板类的构造函数 class MyTemplatePlugin(application: Application) extends TemplatesPlugin
到
class MyTemplatePlugin(application: play.Application) extends TemplatesPlugin