【发布时间】:2016-07-13 18:36:16
【问题描述】:
我正在使用 spring 3.0.5 和 tomcat 7
我在做什么:
我在 JSP 中创建了一个选择元素表。每个选择都与我的模型中的一个 id 相关联,如下所示:
<form:form commandName="someStuff" method="post" id="peopleForm" onSubmit="return validate('${someStuff}');">
<%-- A bunch of other unrelated stuff here --%>
<table>
<th>some other info</th>
<th>please select a name</th>
<c:forEach var="thisThing" items="${allOfTheThings}">
<tr>
<td>some other info here</td>
<td>
<form:select id="name_for_thing_${thisThing.SomeId}" path = "tempNames['${thisThing.SomeId}']" thisThingsId="${thisThing.SomeId}" class="thing_name_selector_class">
<option value="Please Select One">Please Select One</option>
<option value="John">John</option>
<option value="Joe">Joe</option>
<option value="Stephen">Stephen</option>
<option value="Mary">Mary</option>
</form:select >
</td>
</tr>
</c:forEach>
</form:form>
然后在我的域对象“someStuff”中
我定义了一个像这样的地图:
private Map<String, String> tempNames;
public Map<String, String> getTempNames() {
return tempNames;
}
public void setTempNames(Map<String, String> tempNames) {
this.tempNames = tempNames;
}
问题:
如果我从下拉列表中选择值并提交此表单,我可以在控制器中放置一个断点并看到“tempNames”中包含所有正确的值,我可以处理和保存 - 这正是我所做的'd期望 - 所以绑定以一种方式工作......
但是,如果“someStuff”中已有值,则这些值不会绑定到下拉列表。
我试过了
为元素本身添加一个“值”属性,例如:
<form:select id="name_for_thing_${thisThing.SomeId}" path = "tempNames['${thisThing.SomeId}']" value="tempNames['${thisThing.SomeId}']" thisThingsId="${thisThing.SomeId}" class="thing_name_selector_class">
还有这样的:
<form:select id="name_for_thing_${thisThing.SomeId}" path = "tempNames['${thisThing.SomeId}']" value="${tempNames[thisThing.SomeId]}" thisThingsId="${thisThing.SomeId}" class="thing_name_selector_class">
但是第二个似乎甚至没有出现在生成的 HTML 中......
【问题讨论】:
标签: spring jsp spring-form