我尝试使用 Play framework 2.1.1 和 scala 验证注册表单。我有
编译错误:类型不匹配;找到:(字符串,字符串,字符串,字符串,字符串,字符串,字符串,整数)=> 模型。需要联系:(字符串,字符串,字符串,字符串,字符串,(字符串,字符串),字符串,整数)=>?
模型.scala:
package models
case class Contact(firstname: String, lastname: String, jobtitle: String, phone:String, email: String, password: String, companyname: String, employeescount: Int)
应用程序.scala:
val contactForm = Form(
mapping(
"firstname" -> nonEmptyText(minLength=2, maxLength=10),
"lastname" -> nonEmptyText(minLength=2, maxLength=10),
"jobtitle" -> nonEmptyText(minLength=2, maxLength=10),
"phone" -> nonEmptyText(minLength=2, maxLength=10),
"email" -> (email verifying nonEmpty),
"password" -> tuple(
"main" -> text(minLength = 6),
"confirm" -> text
).verifying(
// Add an additional constraint: both passwords must match
"Passwords don't match", { case (p1, p2) => p1 == p2 }
).transform({case (p, _) => p}, {p => p -> p}),
"companyname" -> nonEmptyText,
"employeescount" -> number
)(Contact.apply)(Contact.unapply)
)
index.scala.html
@form(routes.Application.save()) {
@text(contactForm("firstname"), '_label -> "First Name : ", 'toto -> "titi")
@text(contactForm("lastname"), '_label -> "Last Name : ", 'toto -> "titi")
@text(contactForm("jobtitle"), '_label -> "Job Title : ", 'toto -> "titi")
@text(contactForm("phone"), '_label -> "Phone : ", 'toto -> "titi")
@text(contactForm("email"), '_label -> "Email : ")
@password(contactForm("password.main"), '_label -> "Password : ")
@password(contactForm("password.confirm"), '_label -> "Confirm Password : ")
@text(contactForm("companyname"), '_label -> "Company Name : ", 'toto -> "titi")
@select(
contactForm("employeescount"),
options(
"0" -> "0-10",
"1" -> "10-100",
"2" -> "100-1000",
"2" -> " > 1000"
),
'_label -> "Employees"
)
<input type="submit" value="Submit">
}