I'll throw out some ideas. I'm not sure if this will exactly solve your problems, but.. I think you should create a service class to save all your books, since this is a good use case for a transaction. If you save them one by one, any duplicates should fail to save() with a constraint error. Then you can roll back the transaction* and have your controller redisplay the form (which will print all the errors on your book objects.) Also check out the unique constraint (looks like you coded your own?)
* i don't know how to rollback a transaction off the top of my head - someone else can jump in or you can research that..
On Wed, May 14, 2008 at 4:21 PM, Martin Flower <
sylvestris@...> wrote:
Complete Grails/Groovy newby here ...
My create screen has one Book per row (isbn, title). I want to enforce unique isbn and unique name. I can code this contraint in the Book class, but when I Book.findByIsbn(val), I am only searching on the persisted Books, not on those that have not yet been saved. If I have the same Book multiple times on the create screen, but none of which are saved, then no error is detected by the contraints. When I call save(), the first one is saved and the others are discarded.
The screen is defined as an array of Strings. Should I be using a Command object - Books, or maybe Book[] ?
I have been playing around with passing the array of input parameters to the Book class for picking up by the contraints ....
I have been looking to put the validation in the BookController, but I can't work out how to attach the error condition to the Book so that it gets displayed on the screen.
I think I'm tying myself in knots ... time to ask for some help
Thanks
Martin
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email