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.
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]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With