问题
<#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
.
回答1:
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>
回答2:
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.
回答3:
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="..." />
来源:https://stackoverflow.com/questions/8006163/spring-forminput-in-list-iterator