斯卡拉和玩!框架形式错误

时间:2014-02-03 15:59:12

标签: scala playframework-2.0

我已实施此表单

val contactForm : Form[Contact] = Form(

                 mapping(
                "id" -> ignored(NotAssigned: anorm.Pk[Long]),
                "fax" -> longNumber,
                "person" ->nonEmptyText,
                "mobilePhone" -> longNumber,
                "phone" -> longNumber,
                "email" -> nonEmptyText,
                "supplierId"-> mapping(
                                    "id" -> ignored(NotAssigned: anorm.Pk[Long]),
                                    "identityId" -> mapping(
                                                "id" -> ignored(NotAssigned: anorm.Pk[Long]),
                                                "codiceFornitore" -> number,
                                                "supplierType" -> nonEmptyText,
                                                "ragioneSociale" -> nonEmptyText,
                                                "partitaIva" -> longNumber,
                                                "isProduction" -> boolean //act as boolean 0=FALSE
                                    )(SupplierIdentity.apply)(SupplierIdentity.unapply),
                                    "addressId" ->  mapping(
                                                "id" -> ignored(NotAssigned: anorm.Pk[Long]),
                                                "via" -> nonEmptyText,
                                                "cap" -> number,
                                                "comune" -> nonEmptyText,
                                                "provincia" -> nonEmptyText,
                                                "paese" -> nonEmptyText
                                    )(Address.apply)(Address.unapply),
                                    "userId" -> mapping(
                                            "id" -> ignored(NotAssigned: anorm.Pk[Long]),
                                            "name" -> nonEmptyText
                                    )(User.apply)(User.unapply))
                (Supplier.apply)(Supplier.unapply)          
            )(Contact.apply)(Contact.unapply)   
    )`

联系人,SupplierIdentity,供应商,地址和用户均为案例类别。 这是我的模板

@(supplier: Supplier, contactForm : Form[Contact])
.
.
.
@form(routes.FinanceController.addContact(supplier.id.get)) {



                @helper.input(contactForm("fax"), '_id -> "fax", '_label->"Fax" , '_error -> contactForm.error("fax")) { (id, name, value, args) => 
                <input type="text" id="@id" name="@name" value="" @toHtmlArgs(args)>
                }
                @helper.input(contactForm("person"), '_id -> "person", '_label->"Figura di Riferiment", '_error -> contactForm.error("person")) { (id, name, value, args) => 
                <input type="text" id="@id" name="@name" value="" @toHtmlArgs(args)>
                }
                @helper.input(contactForm("mobilePhone"), '_id -> "mobilePhone", '_label->"Cellulare", '_error -> contactForm.error("mobilePhone")) { (id, name, value, args) => 
                <input type="text" id="@id" name="@name" value="" @toHtmlArgs(args)>
                }
                @helper.input(contactForm("phone"), '_id -> "phone", '_label->"Cellulare", '_error -> contactForm.error("phone")) { (id, name, value, args) => 
                <input type="text" id="@id" name="@name" value="" @toHtmlArgs(args)>
                }
                @helper.input(contactForm("email"), '_id -> "email", '_label->"E-mail", '_error -> contactForm.error("email")) { (id, name, value, args) => 
                <input type="text" id="@id" name="@name" value="" @toHtmlArgs(args)>
                }
                @helper.input(contactForm("supplierId"), '_id -> "supplierId", '_error -> contactForm.error("supplierId")) { (id, name, value, args) => 
                <input type="hidden" id="@id" name="@name" value="@{supplier}" @toHtmlArgs(args)>
                }

            <input type="submit" value="Create">
             }

但是当我尝试使用它时,我收到了这个错误:

  

列表(FormError(supplierId.identityId.codiceFornitore,error.required,列表()),   FormError(supplierId.identityId.supplierType,error.required,列表()),   FormError(supplierId.identityId.ragioneSociale,error.required,列表()),   FormError(supplierId.identityId.partitaIva,error.required,列表()),   FormError(supplierId.addressId.via,error.required,列表()),   FormError(supplierId.addressId.cap,error.required,列表()),   FormError(supplierId.addressId.comune,error.required,列表()),   FormError(supplierId.addressId.provincia,error.required,列表()),   FormError(supplierId.addressId.paese,error.required,列表()),   FormError(supplierId.userId.name,error.required,列表()))

我真的陷入了这个错误,我无法得到错误的位置,我没有任何列表!

感谢。

1 个答案:

答案 0 :(得分:0)

错误消息中的路径表示表单中未考虑的表单元素。例如,错误FormError(supplierId.identityId.supplierType,error.required,List())表示您视图中的表单未提供Contact.Supplier.SupplierIdentity.SupplierType的值。

我怀疑你希望将整个Supplier包含在您的Contact中,只包含ID(因为您调用了字段supplierId)。我会重新审视您的Form[Contact]定义,甚至是Contact本身的定义。