3
<#list flowList as flow>
    <@spring.formInput "flow.createDatetime" />
</#list>

flowList is arrayList.

freemarker.template.TemplateModelException: Method public org.springframework.web.servlet.support.BindStatus org.springframework.web.servlet.support.RequestContext.getBindStatus(java.lang.String) throws java.lang.IllegalStateException threw an exception when invoked on org.springframework.web.servlet.support.RequestContext@8bc713e with arguments of types [java.lang.String,]
    at freemarker.ext.beans.OverloadedMethodModel.exec(OverloadedMethodModel.java:134)
    at freemarker.core.MethodCall._getAsTemplateModel(MethodCall.java:93)

How can I resolve @spring.formInput in #list.

skaffman
  • 398,947
  • 96
  • 818
  • 769
Ickhyun Kwon
  • 1,675
  • 4
  • 13
  • 17

3 Answers3

2

Have you tried doing an intermediate assign? I saw this problem on other StackOverflow pages, like Freemarker syntax for a form for a collection of objects (Spring 3 MVC):

<#list flowList as flow>
   <#assign flowDate = flow.createDatetime />
   <@spring.formInput "flowDate" />
<\#list>
Community
  • 1
  • 1
Danalog
  • 559
  • 11
  • 21
0

The following workaround works for me, but is pretty ugly:

<#list flowList as flow>
    <#assign index=flowList?seq_index_of(flow)>
    <@spring.formInput "flowList[${index}].createDatetime" />
</#list>

When the above form is posted, you'll need to ensure that the flow-list is pre-populated with empty flows. Alternatively, just using Spring's AutoPopulatingList as the flow-list implementation.

Muel
  • 4,309
  • 1
  • 23
  • 32
0

For spring to bind the object, the exact reference must be provided. Hence you need to add the index in the tag. This is needed when you post the form back and want the flowlist object as request body in a controller method.

<#list flowList as flow>
    <@spring.formInput "flowList[${flow_index}].createDatetime" />
</#list>

After rendering if you look at the HTML it would be like

<input type="text" id="flowList0.createDatetime" name="flowList[0].createDatetime" value="..." />
Brandon Minnick
  • 13,342
  • 15
  • 65
  • 123
Adnan Mamajiwala
  • 578
  • 3
  • 9
  • 21