Let me bring you up to speed, I have the following class
my controllerCode:public class MyBean{ private String firstName; private String lastName; // getters and setters }
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?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 }
I tried this and it didn't work. Fields have the default values.
Thank you for your help in advance!Code:<c:forEach var="myBean" items="${beans}"> <form:form method="POST" modelAttribute="myBean" action="/do-it"> <%-- inputs, buttons and whatnot --%> </form:form> </c:forEach>


Reply With Quote
