を何をやっている私は私がやっている何を春3.0.5とTomcat 7春フォーム+ JSP:マップ<文字列、文字列>に<select>の値をバインド - 私が間違っ
を使用しています:
を私はJSPでselect要素のテーブルを作成しました。それぞれのは、このように、私のモデルに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'に正しい値がすべて入っていることを確認できますこれはちょうど私が期待しているものなので、バインディングは一方向に働きます...
しかし、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">
しかし、第2 1にはありません結果のHTMLにも表示されているようです....