0

I have an Invoice

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

class InvoiceItem{
    String description
    double price
    double qty
}

My issue is with form validation. If a user enters a string or invalid number format in either price or qty I get a

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

BUT the error is in the Invoice object NOT in the LineItems object therefore I cannot highlight in RED the form appropriately. (And field value remains at zero when displayed so message is somewhat meaningless to user)

I was thinking of using COMMAND object with String parameters and validating their numeric value but I can't figure how to bind the InvoiceItem List.

What is the appropriate Grails way?

I could do all validation on the client side in javascript but that is not my question

Community
  • 1
  • 1

1 Answers1

0

You can do it with command objects. You need to read:

http://blog.peterdelahunty.com/2009/01/cool-way-to-dynamically-add-entries-to.html

command object data binding

Grails command object data binding

http://grails.1312388.n4.nabble.com/validating-nested-command-objects-td1346994.html

Community
  • 1
  • 1
AA.
  • 4,496
  • 31
  • 35
  • Almost ! lazy list certainly puts me in the right direction but the child items are repeated in the command list. See Grails JIRA GRAILS-9371 http://jira.grails.org/browse/GRAILS-9371 – Stephane Rainville Sep 04 '12 at 02:25