user1463172
user1463172

Reputation: 101

"Method mapping in object Forms" Error

I am trying to build a basic application using the Play Framework with Scala, I have tried to copy from the forms example supplied but have now got stuck.

On refresh in the browser I am getting the following error.

enter image description here

I have been through all the files on the sample but can't seem to workout where the issue is, I am very new to this and the reason is probably very simple but I am afraid that this time Google has let me down.

If someone is able to point me in the right direction I would be very grateful.

Thanks

The Code from the main files

/Controllers/Submissions

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/Contact

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>

   }

}

Upvotes: 1

Views: 95

Answers (1)

Schleichardt
Schleichardt

Reputation: 7552

See http://www.playframework.com/documentation/2.1.x/ScalaForms

The mapping method just lets you define your custom functions. When you want to construct and deconstruct a case class, you can just use its default apply and unapply functions, as they do exactly that!

How the signature of mapping exactly is, you find on 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)
)

Upvotes: 2

Related Questions