Играть!Ошибка перегруженного метода отображения значений с альтернативами? - PullRequest
3 голосов
/ 27 марта 2012

Определение формы в моей игре! контроллер, когда компилятор выдает эту странную ошибку: overloaded method value mapping with alternative:...[a bunch of crap]...Error occurred in an application involving default arguments.

Вот код, я не совсем уверен, в чем может быть причина:

 val jobForm: Form[Job] = Form(
    mapping(
      "id" -> of[Long],
      "end_time" -> text(minLength = 3),
      "start_time" -> text(minLength = 3),
      "client_id" -> of[Long],
      "start_address_type" -> text,
      "start_address" -> text(minLength = 3),
      "start_city" -> text(minLength = 3),
      "start_province" -> text(minLength = 2),
      "start_lat" -> optional(text),
      "start_lng" -> optional(text),
      "comments" -> text,
      "created" -> text,
      "modified" -> text,
      "canceled" -> of[Boolean],
      "started" -> of[Boolean],
      "completed" -> of[Boolean],
      "user_id" -> optional(of[Long]),
      "start_order" -> optional(number),
      "end_order" -> optional(number),
      "account_id" -> of[Long]
    )(Job.apply)(Job.unapply)
  )

1 Ответ

4 голосов
/ 27 марта 2012

Посмотрел Play! 2.0 источник. Похоже, у вас может быть только 18 аргументов максимум на mapping(), поэтому мне пришлось начать вложение и создавать новые классы дел. Вот результат:

val jobForm: Form[JobSimple] = Form(
    mapping(
      "id" -> of[Long],
      "end_time" -> text(minLength = 3),
      "start_time" -> text(minLength = 3),
      "client_id" -> of[Long],
      "location" -> mapping(
        "start_address_type" -> text,
        "start_address" -> text(minLength = 3),
        "start_city" -> text(minLength = 3),
        "start_province" -> text(minLength = 2),
        "start_lat" -> optional(text),
        "start_lng" -> optional(text)
        )(JobLocation.apply)(JobLocation.unapply),
      "comments" -> text,
      "created" -> text,
      "modified" -> text,
      "canceled" -> of[Boolean],
      "started" -> of[Boolean],
      "completed" -> of[Boolean],
      "user_id" -> optional(of[Long]),
      "start_order" -> optional(number),
      "account_id" -> of[Long]
    )(JobSimple.apply)(JobSimple.unapply)
  )
...