Im using grails 1.3.7 and here is the case...
Have a huge form with a few different for its fields (later used in data binding) and trying to validate thru a ... 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? (后来用于数据绑定),并试图通过进行验证...但是,前缀中使用的可爱的DOT给我带来了麻烦,并且无法正确映射名称在命令对象中...有什么建议吗?
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
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
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.