对象集合表单的 Freemarker 语法 (Spring 3 MVC)
我有一个命令 bean (FooList
),它有一个集合属性(Foo
beans 的 List
)。
我正在尝试创建一个可以同时编辑所有 Foo 的表单。我发现了许多如何使用 JSP 执行此操作的示例,但我在将这些示例转换为 Freemarker 语法时遇到了麻烦。
在我的 Freemarker 模板中,我可以轻松地迭代集合:
[#list fooList.foos as foo]
...
[/#list]
我还可以通过索引引用特定的 Foo
:
[@spring.bind "fooList.foos[0].name" /]
<input type="text" name="${spring.status.expression}" value="${spring.status.value?default('')}"/>
但是,我还没有弄清楚如何同时执行这两个操作,将所有 Foo 绑定到表单元素。
这是一个失败的天真的尝试:(
[#list fooList.foos as foo]
[@spring.bind "fooList.foos[foo_index].name" /]
...
[/#list]
${foo_index}
本身在循环内工作。)
任何人都可以指出我正确的方向吗?
谢谢。
I have a command bean (FooList
) which has a property which is a collection (a List
of Foo
beans).
I'm trying to create a form which can edit all the Foo
s at once. I have found many examples of how to do this using JSP, but I'm having trouble translating these to Freemarker syntax.
In my Freemarker template, I can easily iterate over the collection:
[#list fooList.foos as foo]
...
[/#list]
I can also refer to a particular Foo
by index:
[@spring.bind "fooList.foos[0].name" /]
<input type="text" name="${spring.status.expression}" value="${spring.status.value?default('')}"/>
However, I haven't yet worked out how I can do both at the same time, to bind all the Foo
s to form elements.
Here's one naïve attempt which failed:
[#list fooList.foos as foo]
[@spring.bind "fooList.foos[foo_index].name" /]
...
[/#list]
(On its own, ${foo_index}
works inside the loop.)
Can anyone point me in the right direction?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
刚刚遇到了同样的问题。这对我有用:
Just had the same problem. This worked for me:
尝试一下,
根据 列表指令。
Try,
The foo in that example will reference each item in the list one by one, according to the freemarker documentation on the list directive.
我认为应该是这样的:
I think it should be as follows: