我正在尝试使用Play框架和Scala构建一个基本应用程序,我试图从提供的表单示例中复制但现在已经卡住了。
在浏览器中刷新时,我收到以下错误。
我已经浏览了样本上的所有文件,但似乎无法解决问题所在,我对此非常陌生并且原因可能非常简单但我担心这次谷歌让我失望了
如果有人能指出我正确的方向,我将非常感激。
由于
主要文件中的代码
/控制器/提交
object Submission extends Controller {
val contactForm:Form[Contact] = Form(
mapping(
"title" -> text,
"firstname" -> text,
"lastname" -> text,
"gender" -> text,
"dob" -> text,
"mobile" -> text,
"landline" -> text,
"email" -> text,
"housenumber1" -> text,
"housename1" -> text,
"address11" -> text,
"address12" -> text,
"address13" -> text,
"address14" -> text,
"address15" -> text,
"postcode1" -> text,
"country1" -> text )
)
def submit = TODO
/模型/联系
package models
case class Contact(
title: String,
firstname: String,
lastname: String,
gender: String,
dob: String,
mobile: String,
landline: String,
email: String,
housenumber1: String,
housename1: String,
address11: String,
address12: String,
address13: String,
address14: String,
address15: String,
postcode1: String,
country1: String
)
/views/application.scala.html
@(contactForm: Form[Contact])
@import helper._
@import helper.twitterBootstrap._
@title = {Overseas Application}
@main(title) {
@helper.form(action = routes.Submission.submit) {
<fieldset>
<legend>Personal Information</legend>
@inputText(contactForm("title"),'_label -> "Title")
@inputText(contactForm("firstname"),'_label -> "First Name")
@inputText(contactForm("lastname"),'_label -> "Last Name")
@inputText(contactForm("gender"),'_label -> "Gender")
@inputText(contactForm("dob"),'_label -> "Date of Birth")
@inputText(contactForm("mobile"),'_label -> "Mobile")
@inputText(contactForm("landline"),'_label -> "Landline")
@inputText(contactForm("email"),'_label -> "Email")
</fieldset>
<fieldset>
<legend>Address 1</legend>
@inputText(contactForm("housenumber1"),'_label -> "House Number (1)")
@inputText(contactForm("housename1"),'_label -> "House Name(1)")
@inputText(contactForm("address11"),'_label -> "Address Line 1 (1)")
@inputText(contactForm("address12"),'_label -> "Address Line 2 (1)")
@inputText(contactForm("address13"),'_label -> "Address Line 3 (1)")
@inputText(contactForm("address14"),'_label -> "Address Line 4 (1)")
@inputText(contactForm("address15"),'_label -> "Address Line 5 (1)")
@inputText(contactForm("postcode1"),'_label -> "Postcode (1)")
@inputText(contactForm("country1"),'_label -> "Country (1)")
</fieldset>
<div class="actions">
<input type="submit" class="btn primary" value="Submit">
</div>
}
}
答案 0 :(得分:2)
请参阅http://www.playframework.com/documentation/2.1.x/ScalaForms
映射方法只允许您定义自定义函数。当你 想构建和解构一个case类,你可以使用它 默认应用和取消应用函数,就像它们完全一样!
您在http://www.playframework.com/documentation/2.1.x/api/scala/index.html#play.api.data.Forms $。
上找到了映射的签名val userForm:Form[Contact] = Form(
mapping(
"title" -> text,
"firstname" -> text,
"lastname" -> text,
"gender" -> text,
"dob" -> text,
"mobile" -> text,
"landline" -> text,
"email" -> text,
"housenumber1" -> text,
"housename1" -> text,
"address11" -> text,
"address12" -> text,
"address13" -> text,
"address14" -> text,
"address15" -> text,
"postcode1" -> text,
"country1" -> text
)(Contact.apply)(Contact.unapply)
)