テーブル内のデータ (チェックボックス) を編集しようとしています。しかし、送信ボタンをクリックすると、コントローラーのフォームは空です
thymeleaf の例が見つからなかったので、この例を適応させました
私はフォームオブジェクトを使用します:
public class MyForm {
private List<MyObj> data;
// ...
}
2 つのメソッド (GET と POST) を持つコントローラー:
@RequestMapping(value="/edit/", method = RequestMethod.GET)
public String editGet(Model model) {
MyForm form = new MyForm(data);
model.addAttribute("myForm", form);
return "editPage";
}
@RequestMapping(value="/edit/save", method = RequestMethod.POST)
public String editPost(@ModelAttribute("myForm") MyForm myForm, Model model) {
// here myForm.getData() is empty
}
そして私のhtml:
<form th:action="@{/edit/save}" th:object="${myForm}" method="POST">
<table>
<thead>....</thead>
<tbody th:each="myObj : *{data}" th:remove="tag">
<tr>
<td><span th:text="${myObj.name}"></span></td>
<td><input type="checkbox" th:checked="${myObj.isOK}"/></td>
</tr>
</tbody>
</table>
<input type="submit">Save</input>
</form>
私は何を忘れましたか?