0

I have a g:form in my GSP with field names like "email-address", "passwd", and "passwd-confirm".

I also have a Command object with properties like "email", "password", and "passwordConfirm".

In my controller action I would like Grails to bind the form fields to a new Command object:

def register(RegistrationCommand registration) {
   // do something with registration.email, registration.password, etc.
}

It looks like Grails is trying to bind request parameters to the Command object by name. Is there any way I can customize that binding so my form params can bind to Command object properties whose names don't match?

erturne
  • 1,799
  • 1
  • 15
  • 29
  • One of the main benefits of Command Objects is to cater them to your form needs when they don't align with Domain properties. Fix your input element names, problem solved. – Gregg May 12 '13 at 04:03
  • I have two workarounds (the one you mentioned by changing form values or Command properties to match, or constructing an instance in my controller action using controller action parameters bound via @RequestParameter). I'm really more interested if there's actually a way to have form field names different from Command property names. The purist in me doesn't like the idea of changing my CSS ids and classes to use camel-case. I'm OCD, so I'd have to change my convention everywhere! ;-) – erturne May 12 '13 at 05:00
  • You'll either have to rename your properties to match the field names or write your own binding utility. Assuming your own conventions are consistent, you can loop through your bean properties and set values as needed firstName -> input_FirstName, lastName -> input_LastName, etc. – rimero May 12 '13 at 06:57

0 Answers0