[英]Spring MVC multiple rows form submit submits new ModelAttribute
Ok its another one of spring's null ModelAttribute but I've tried everything I found but it doesn't work. 好的,它是spring的null的ModelAttribute的另一个值,但是我已经尝试了所有发现的方法,但是它不起作用。
I've adding this tutorials functionality to my web app spring-mvc everythings workds greate except for when I have to get the data back from the form to my bean. 我已将此教程功能添加到我的Web应用程序spring-mvc一切都很好,除了当我必须将数据从表单返回到bean时。
I use two post methods 我使用两种张贴方法
@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";
}
the first one works fine and i can see the data in my Jsp, the second one gets a new ModelAttribute. 第一个工作正常,我可以在我的Jsp中看到数据,第二个得到一个新的ModelAttribute。
This is my form 这是我的表格
<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>
what seems to be wrong here ? 这里似乎有什么问题? PS i tried my inputs with and without a type attribute and still it gets null, and as I said i can see my data but i can't submit them.
PS我尝试了带有和不带有type属性的输入,但它仍然为null,正如我说的,我可以看到我的数据,但无法提交。
Have you tried adding the following annotation to the top of your controller class ? 您是否尝试过将以下注释添加到控制器类的顶部?
@SessionAttributes({ "editForm" })
public class YourController {
...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.