I encountered a curious bug today. A form which allows the user to edit an object and use check boxes to specify relationships to child objects stopped saving the state when some of them were checked. I assumed it was a data issue since only some of the child objects were impacted. As it turns out, using fieldValue in the definition of IDs for the check boxes was to blame. Specifically it's habit of formatting integers was to blame.
Here are the details on my situation. I had an edit page for objects of type Car and an array of check boxes to associate the Car object with its equipped accessories which were of type Accessory. The accessory I most recently added, 'Dashboard Jesus' would never stay checked.
After some fumbling around I noticed that my instantiation of the list of check boxes using a collection of Accessory objects, which used the object IDs for the check box names, had commas in it! My most recent ID has broken the 1000 barrier on my ID sequence. This caused the ID for Dashboard Jesus, and hence the HTML element ID, to be represented as 1,000.
Lessons learned:
fieldValuemay format your data (including adding commas to an integer) so never, ever use it for anything other than the contents of a field.- Stuff in grails may format your IDs if you're not careful. To catch bugs early bump your sequence to a number grater than 1000. This may be possible in grails, but it seems complicated. I solved the problem simply by using a database tool to bump up my sequence value after Grails set up the database.
