对象集合表单的 Freemarker 语法 (Spring 3 MVC)

发布于 2024-10-03 08:34:23 字数 779 浏览 5 评论 0原文

我有一个命令 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 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.

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 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]

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

Can anyone point me in the right direction?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

无悔心 2024-10-10 08:34:23

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

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

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]
你对谁都笑 2024-10-10 08:34:23

尝试一下,

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

根据 列表指令

Try,

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

The foo in that example will reference each item in the list one by one, according to the freemarker documentation on the list directive.

木緿 2024-10-10 08:34:23

我认为应该是这样的:

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

I think it should be as follows:

[#list fooList.foos as foo]
    [@spring.bind "fooList.foos[" + foo_index + "].name" /]
    ...
[/#list]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文