I can't customize the view propose by the module securesocial for play2, "not found: type RequestHeader "

StackOverflow https://stackoverflow.com/questions/13826586

  •  07-12-2021
  •  | 
  •  

Frage

I'm trying to customize the view propose by the module "securesocial" with play 2

What I've already done is :

1/ Create a new plugin name SecureViewsPlugin that implements the TemplatesPlugin under "controllers/SecuresViewsPlugin.scala"

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/ I updated the file play.plugins with :

1500:com.typesafe.plugin.CommonsMailerPlugin
9996:securesocial.core.providers.utils.DefaultPasswordValidator
9997:controllers.SecureViewsPlugin

3/ I made a copy a the different view in the folder "views/secure"

/Views
     /secure
         /inputFieldConstructor.scala.html
         /login.scala.html
         /(...)

Here is the begining of the error I always get

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

I tried to delete "(implicit request: RequestHeader)" but then I got this error

type mismatch; found : play.api.data.Form[(String, String)] required: play.data.Form[(java.lang.String, java.lang.String)]

I'm guessing I'm not doing it the right way.

I can't figure out why I'm getting these errors

War es hilfreich?

Lösung

I had the same problem, or very similar. See if this can help you:

Error:

[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]

Cause:

I think this is because the securesocial uses scala on your router and I use Java in my Play project. The RequestHeader sent is in Scala (play.api.mvc.RequestHeader) but my template was expecting in Java (play.mvc.RequestHeader).

Solution

To solve this I changed in my custom login.scala.html:

@(loginForm: play.api.data.Form[(String,String)], errorMsg: Option[String] = None)(implicit request: RequestHeader)

To this:

@(loginForm: play.api.data.Form[(String,String)], errorMsg: Option[String] = None)(implicit request: play.api.mvc.RequestHeader)

Andere Tipps

You have to do the following:

in all the Views/secure/...*.scala.html files:

Replace: RequestHeader with play.api.mvc.RequestHeader Form[String, String] or Form[String] with play.api.data.Form

for e.g. in startSignUp.scala.html file, change the original:

@(startForm:Form[String])(implicit request: RequestHeader)

with

@(startForm:play.api.data.Form[String])(implicit request: play.api.mvc.RequestHeader)

Abbas mentioned the first step to get your own templating working.

But for me it still didn't work out. This exception was thrown:

play.api.PlayException: Cannot load plugin [Plugin [controllers.MyTemplatePlugin] cannot been instantiated.]
...
Caused by: java.lang.NoSuchMethodException: controllers.MyTemplatePlugin.<init>(play.Application)

A fix for this problem was to adapt the constructor of the template class from

class MyTemplatePlugin(application: Application) extends TemplatesPlugin

to

class MyTemplatePlugin(application: play.Application) extends TemplatesPlugin

This fix was proposed by the securesocial maintainer jaliss on https://github.com/jaliss/securesocial/issues/99

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top