grails 命令对象和带有前缀的字段
我使用 grails 1.3.7,情况如下...
有一个巨大的表单,其字段有几个不同的前缀(稍后用于数据绑定),并尝试通过命令对象进行验证...但是,在前缀给我带来了困难,无法在命令对象中正确映射名称...请问有什么建议吗?
表单中具有类似这样的字段:
<input name="dealer.name" value="${dealer.name}" type="text">
对于命令对象:
class somethingCommand {
String name
Map dealer = [:]
static constraints = {
dealer validator: {
val, obj ->
obj.properties["name"] != ""
}
}
}
如果......我们会怎样?以另一种方式查看它并在传递给命令之前映射参数对象...我应该如何在不使用 grails 魔法的情况下将参数传递给命令对象?!?!?!
tnx
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以通过在控制器中获取“经销商”地图
,然后手动创建经销商命令对象并将地图内容绑定到它。
然后您可以正常使用命令对象的验证
you could grab the "dealer" map in the controller via
and then create a dealer command opject by hand and bind the map content to it.
you can then use the validation of the command object as normal
支持带有命令对象前缀的数据绑定属性:
对于命令:
名为“name”、“dealer”、“dealer.name”和“dealer.dealer”的属性将正确绑定到命令对象。
http://grails.org/doc/2.3.x/guide/single .html#commandObjects
Databinding properties with prefixes to command objects is supported:
For the command:
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