播放表单映射以获取特征实例列表

时间:2017-01-12 17:08:33

标签: playframework

我有一些实现特征信息的类和一个包含信息列表的UserData类。列表中的元素可以是此类的实例(例如,DriverInfo,TaskerInfo)。现在,我想为UserData创建一个播放表单,我该如何进行映射?我大多被困在List [Info]。我添加了列表以避免创建2个UserData实例,因为用户可以填写两个表单。

case class DriverInfo(licensePlate: String, maker: String, carType: String, model: String, yearOfModel: String, engine: String) extends Info

case class TaskerInfo(primaryService: String, otherServices: List[String], id: String, idType: String) extends Info

case class UserData(name: Option[String], firstName: String, lastName: String, info: List[Info])

这是我到目前为止所做的,但它不起作用。 val driverForm = Form( mapping( "name" -> optional(nonEmptyText), "firstName" -> nonEmptyText, "lastName" -> nonEmptyText, "email" -> email.verifying(maxLength(250)), "password" -> nonEmptyText.verifying(minLength(6)), "info" -> list( mapping( "licensePlate" -> nonEmptyText, "maker" -> nonEmptyText, "carType" -> nonEmptyText, "model" -> nonEmptyText, "yearOfModel" -> nonEmptyText, "engine" -> nonEmptyText)(DriverInfo.apply)(DriverInfo.unapply)))(UserData.apply)(UserData.unapply))

0 个答案:

没有答案