【发布时间】:2015-01-07 06:58:20
【问题描述】:
(Grails 版本:2.3.11,Groovy 版本:2.2.2)
我是 Groovy 和 Grails 的新手,所以如果我遗漏了一些明显的东西,请原谅我。我有一个包含 Map 的命令对象,键是整数(尽管我尝试过字符串,但它们也不起作用),值是 Details 对象的列表:
class Details {
Integer volume
Double price
}
class TheCommand {
Map<Integer, List<Details>> details = [:].withDefault { [].withLazyDefault { new Details() } }
String location
}
我的 GSP 中有这个:
<g:form controller="mapOfLists" action="create">
<g:textField name="location" size="7"/>
<table>
<g:each in="${(1..24)}" var="hour">
<tr>
<td>${hour}</td>
<g:each in="${(0..4)}" var="column">
<td><g:textField name="details[${hour}][${column}].price" size="4"/></td>
<td><g:textField name="details[${hour}][${column}].volume" size="3"/></td>
</g:each>
</tr>
</g:each>
</table>
<g:submitButton name="Submit" value="Submit"/>
</g:form>
以及行动:
// trying the different binding approaches, none work
def create(TheCommand theCommand) {
// theCommand.hasErrors() -> false
// at this point theCommand's details is an empty map, I can see the details[x][y] values in the params object
bindData(theCommand, params)
// the bindData above didn't work, details is still an empty map
theCommand.properties['details'] = params
// the setting via properties above didn't work, details is still an empty map
}
两个问题: 1)关于尝试什么的任何想法?我已经看到有一种使用自定义活页夹的方法,但这似乎是 grails 应该处理的情况,所以我在走这条路之前先试一试。
2) 是否有更强大的数据绑定器?我已经浏览了相关的 SimpleDataBinder 代码,它似乎只支持单索引属性
非常感谢, 赛斯
【问题讨论】:
标签: grails