Pergunta

If I have a command object SomeClassCommand with a String field someField but want to bind data from a parameter params.otherField, how do I go about doing that? Is there an annotation I can put in the command object?

Foi útil?

Solução

Actually there is a horrendous work around which defies the purpose of auto binding in your case.

def map = [:]
map.someField = params.otherField
//plus set all the other params to map
map << params

def commandObj = new SomeCommandObj()

//Explicitly bind map to command object
bindData(commandObj, map)

It really is horrendous, because you are doing extra work only to bind data. You could have directly set values to Command Object.

I would suggest either to change the command object field name or the parameter field name, which ever is controllable. AFAIK there is no annotation available unless you have your own utility to do such.

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