简体   繁体   English

grails命令对象和带有前缀的字段

[英]grails command object and fields with prefixes



Im using grails 1.3.7 and here is the case... 我正在使用grails 1.3.7,情况就是这样...
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? 具有巨大的形式,其字段带有几个不同的前缀 (后来用于数据绑定),并试图通过命令对象进行验证...但是,前缀中使用的可爱的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?!?!?! 如果...。我们以另一种方式看待它并在传递给命令对象之前映射参数...我应该如何在不使用grails magic的情况下将参数传递给命令对象?!?!?!

tnx n

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. 名为“ name”,“ dealer”,“ dealer.name”和“ dealer.dealer”的属性将正确绑定到命令对象。

http://grails.org/doc/2.3.x/guide/single.html#commandObjects 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 然后您可以像平常一样使用命令对象的验证

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM