【发布时间】:2013-05-19 13:15:06
【问题描述】:
好的,它是 spring 的另一个 null ModelAttribute,但我已经尝试了我找到的所有东西,但它不起作用。
我已将本教程功能添加到我的网络应用程序 spring-mvc 中,一切都很好,除非我必须将数据从表单返回到我的 bean。
我用了两种post方法
@RequestMapping(method = RequestMethod.POST)
public String openEdit(@RequestParam("notfound") String[] notFound,
Model model){
EditForm editForm = editModel.createEditForm(notFound);
model.addAttribute("editForm",editForm);
return "Edit/EditOwners";
}
@RequestMapping(method = RequestMethod.POST,value = "/saveOwners")
public String saveOwners(@ModelAttribute("editForm") EditForm editForm){
editModel.addOwners(editForm);
return "index";
}
第一个工作正常,我可以在我的 Jsp 中看到数据,第二个得到一个新的 ModelAttribute。
这是我的表格
<form:form method="POST" action="saveOwners" modelAttribute="editForm" >
<table class="table table-bordered table-striped table-hover table-condensed">
<caption>
<h4>Edit The Owners</h4>
</caption>
<thead>
<tr>
<td>Name</td>
</tr>
</thead>
<tbody>
<c:forEach items="${editForm.owners}" var="item" varStatus="status">
<tr>
<td>${item.name}</td>
<td><input type="text" name="${owners[status.index].outId}" value="${item.outId}" /> </td>
<td><input type="text" name="${owners[status.index].type}" value="${item.type}" /> </td>
</tr>
</c:forEach>
</tbody>
</table>
<input type="submit" value="Save" class="btn btn-primary"/>
</form:form>
这里似乎有什么问题? PS 我尝试了有无类型属性的输入,但它仍然为空,正如我所说,我可以看到我的数据,但我无法提交它们。
【问题讨论】:
标签: java spring spring-mvc