1

我正在尝试使用带有 Scala 的 Play Framework 构建一个基本应用程序,我试图从提供的表单示例中复制,但现在卡住了。

在浏览器中刷新时,我收到以下错误。

在此处输入图像描述

我已经浏览了样本上的所有文件,但似乎无法确定问题出在哪里,我对此很陌生,原因可能很简单,但我担心这一次谷歌让我失望了。

如果有人能够指出我正确的方向,我将不胜感激。

谢谢

主文件中的代码

/控制器/提交

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

/models/联系方式

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>

   }

}
4

1 回答 1

2

请参阅http://www.playframework.com/documentation/2.1.x/ScalaForms

映射方法只允许您定义自定义函数。当你想构造和解构一个案例类时,你可以使用它默认的 apply 和 unapply 函数,它们就是这么做的!

映射的签名究竟是怎样的,您可以在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)
)
于 2013-09-20T17:48:45.913 回答