用于对象集合的表单的Freemarker语法(Spring 3 MVC) [英] Freemarker syntax for a form for a collection of objects (Spring 3 MVC)

查看:141
本文介绍了用于对象集合的表单的Freemarker语法(Spring 3 MVC)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个命令bean(FooList),它的属性是一个集合(Foo bean的List).

I have a command bean (FooList) which has a property which is a collection (a List of Foo beans).

我正在尝试创建一个可以一次编辑所有Foo的表单.我发现了许多使用JSP进行此操作的示例,但是我很难将它们转换为Freemarker语法.

I'm trying to create a form which can edit all the Foos at once. I have found many examples of how to do this using JSP, but I'm having trouble translating these to Freemarker syntax.

在我的Freemarker模板中,我可以轻松地遍历集合:

In my Freemarker template, I can easily iterate over the collection:

[#list fooList.foos as foo]
...
[/#list]

我还可以通过索引引用特定的Foo:

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('')}"/>

但是,我还没有弄清楚如何同时将两个Foo绑定成表单元素.

However, I haven't yet worked out how I can do both at the same time, to bind all the Foos to form elements.

这是一次幼稚的尝试,但失败了:

Here's one naïve attempt which failed:

[#list fooList.foos as foo]
    [@spring.bind "fooList.foos[foo_index].name" /]
    ...
[/#list]

(${foo_index}独自在循环内工作.)

(On its own, ${foo_index} works inside the loop.)

有人能指出我正确的方向吗?

Can anyone point me in the right direction?

谢谢.

推荐答案

遇到了同样的问题.这对我有用:

Just had the same problem. This worked for me:

[#list fooList.foos as foo]
  <#assign item>fooList.foos[${foo_index}].name</#assign>
  [@spring.bind item /]
  ...
[/#list]

这篇关于用于对象集合的表单的Freemarker语法(Spring 3 MVC)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆