Grails 命令对象和输入名称值
我有一个表单,我必须在其中专门订购输入元素。所以我的表单看起来像这样:
<input type="text" name="name"/>
<select name="contacts.first">...</select>
<select name="contacts.second">...</select>
...
我有一个命令对象,我试图用它来验证该表单。但是,我似乎无法正确映射它。我的命令对象如下所示:
@Validatable
class MyCommand {
def name
def contacts
static constraints = { /* ... */ }
}
我的控制器操作如下所示:
def update = { MyCommand cmd ->
if (cmd.validate()) {
/* ... */
}
}
当我查看 cmd.contacts
时,它为 null。如果我将每个选择命名为 contacts
而不是 contacts.first
,那么它就是预期的值数组,但我不想依赖浏览器来确保这些值项目按特定顺序排列。对这项工作有什么建议吗?正确的顺序至关重要。
I have a form where I have to have the input elements ordered specifically. So my form looks something like this:
<input type="text" name="name"/>
<select name="contacts.first">...</select>
<select name="contacts.second">...</select>
...
I have a command object that I'm trying to use to validate this form. However, I can't seem to get it to map correctly. My command object looks like this:
@Validatable
class MyCommand {
def name
def contacts
static constraints = { /* ... */ }
}
My controller action looks like:
def update = { MyCommand cmd ->
if (cmd.validate()) {
/* ... */
}
}
When I look at cmd.contacts
, it's null. If I name each select just contacts
instead of contacts.first
, it is an array of values as expected, but I did not want to depend on the browser to make sure these items are in a specific order. Any suggestions to making this work? The correct order is crucial.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
原始想法:http://stateyourbizness.blogspot。 com/2009/02/binding-to-collection-fields-on-command.html
因此,对于您的命令对象,您可以使用:
并使您的 html 看起来像:
Original idea: http://stateyourbizness.blogspot.com/2009/02/binding-to-collection-fields-on-command.html
So for your command object you could use:
And have your html look like: