我无法使用模型

时间:2015-08-03 12:46:53

标签: forms scala playframework playframework-2.3

在我的Play Scala Project我的表单中有超过18个字段。我从输入type submit插入了一个表单值到DB如果字段是少于18.如果我在18中添加了超过form mapping个字段,则会显示如下错误

missing arguments for method unapply in object EmployeeRegister; follow this method with `_' if you want to treat it as a partially applied function

控制器/ Employees.scala

val employeeForm = Form(
    mapping(
      "employeeid" -> ignored(None: Option[Int]),
      "employeename" -> nonEmptyText,
      "employeedesc" -> nonEmptyText,     
    .....
    .....      
      "languages" -> list(number)   
      )(models.EmployeeRegister.apply)(models.EmployeeRegister.unapply))

模型/ Employee.scala

case class EmployeeRegister(
  employeeid: Option[Int] = None,
  employeename: String,
  employeedesc: String,
  .....
  ......
  languages: List[Int]

  )

我尝试了什么

我使用nested values概念添加了超过18个字段。它没有显示任何错误,但form submission没有工作它转发到同一页面  使用此error handling代码。

employeeForm.bindFromRequest.fold(             

            formWithErrors => BadRequest(html.employeeRegisterForm(formWithErrors),
               employee => {
               ....
               ...
               }

嵌套值

控制器/ Employees.scala

 val employeeForm = Form(
        mapping(
          "employeeid" -> ignored(None: Option[Int]),
          "employeename" -> nonEmptyText,
          "employeedesc" -> nonEmptyText,     
        .....
        ..... 
       "os" -> mapping(
          "operatingsystem" -> text,   
            "osversion" -> text, 
            "osbit" -> text      
        )(models.OS.apply)(models.OS.unapply),
          "languages" -> list(number)   
          )(models.EmployeeRegister.apply)(models.EmployeeRegister.unapply))

模型/ employee.scala

 case class EmployeeRegister(
      employeeid: Option[Int] = None,
      employeename: String,
      employeedesc: String,
      .....
      ......
      os:OS,
      languages: List[Int]

      )

      case class OS(
       operatingsystem: String,   
      osversion: String,
      osbit:String  
    )

0 个答案:

没有答案