【问题标题】:Scala and Play! framework form error斯卡拉和玩!框架形式错误
【发布时间】:2014-02-03 15:59:12
【问题描述】:

我已经实现了这个表单

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)   
    )`

Contact、SupplierIdentity、Supplier、Address 和 User 是 Case Class。 这是我的模板

@(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">
             }

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

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

我真的陷入了这个错误,我无法找到错误在哪里,我没有任何列表!

谢谢。

【问题讨论】:

    标签: scala playframework-2.0


    【解决方案1】:

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

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

    【讨论】:

    • 我怀疑这一点,问题正是我想包含所有 Contact 类,但无论如何谢谢,现在我确切知道我的问题是什么了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-05-18
    • 2013-05-07
    • 1970-01-01
    • 2012-03-17
    • 2017-08-22
    • 2012-06-12
    • 1970-01-01
    相关资源
    最近更新 更多