Grails父子表单验证

时间:2012-08-28 02:55:19

标签: validation grails parent-child

我有发票

class Invoice{
    static hasMany = [lineItems: InvoiceItem]
    double total
}

class InvoiceItem{
    String description
    double price
    double qty
}

我的问题是表单验证。如果用户以价格或数量输入字符串或无效数字格式,我会得到

Failed to convert property value of type java.lang.String 
to required type double for property price

但错误在Invoice对象中而不在LineItems对象中,因此我无法在RED中正确地突出显示该表单。 (当显示时字段值保持为零,因此消息对用户来说有点无意义)

我在考虑使用带有String参数的COMMAND对象并验证它们的数值,但我无法想出如何绑定InvoiceItem列表。

Grails的合适方式是什么?

我可以在javascript中对客户端进行所有验证,但这不是我的问题