IS it possible to build N <form:form>'s from a List of modelAttributes?
Let me bring you up to speed, I have the following class
Code:
public class MyBean{
private String firstName;
private String lastName;
// getters and setters
}
my controller
Code:
@Controller
public class MyController {
@ModelAttribute("myBean")
public MyBean getMyBean() {
return new MyBean();
}
@RequestMapping(value = "/list-beans", method = RequestMethod.GET)
public String getBeans(Model model) {
List<MyBean> beans = new ArrayList<MyBean>();
// add stuff to beans
model.addAttribute("beans", beans);
// return view
}
Now, on my view I want to have as many forms as beans, and to have each bean backing one form. Is this possible to achieve?
I tried this and it didn't work. Fields have the default values.
Code:
<c:forEach var="myBean" items="${beans}">
<form:form method="POST" modelAttribute="myBean" action="/do-it">
<%-- inputs, buttons and whatnot --%>
</form:form>
</c:forEach>
Thank you for your help in advance!