grailsprefixcommand-objects

grails command object and fields with prefixes




Im using grails 1.3.7 and here is the case...
Have a huge form with a few different prefixes for its fields (later used in data binding) and trying to validate thru a command object... however the lovely DOT used in prefixes is giving me a hard time and cannot get the names mapped properly in command object... any suggestion please?

in the form have fields like field like this one:

<input name="dealer.name" value="${dealer.name}" type="text"> 

and for command object:

class somethingCommand {
    String name
    Map dealer = [:]
    static constraints = {
        dealer validator: {
            val, obj ->
            obj.properties["name"] != ""
        }
    }
}

what if.... we look at it in another way and map the parameters before passing to command object... how should I pass my parameters to a command object without using grails magic?!?!?!

tnx


Solution

  • you could grab the "dealer" map in the controller via

    def dealerMap = params["dealer"]
    

    and then create a dealer command opject by hand and bind the map content to it.

    def dealerCommand = new DealerCommand() 
    bindData(dealerCommand , dealerMap)
    

    you can then use the validation of the command object as normal