Pergunta



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

Foi útil?

Solução

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

Outras dicas

Databinding properties with prefixes to command objects is supported:

For the command:

class DealerCommand {
    String name
    Map dealer = [:]
}

Properties named 'name', 'dealer', 'dealer.name' and 'dealer.dealer' will be bound correctly to the command object.

http://grails.org/doc/2.3.x/guide/single.html#commandObjects

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top