KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Suppose I have class Person , I made a list of Person instances and add this list to a Model . List<Person> persons = new ArrayList<Person>(); model.addAttribute("persons",persons); return "savePersons"; In the View page I have a form: <form:form method="post" action="savePerson" modelAttribute="persons"> <c:forEach var="person" items="${persons}"> <form:input path="person.FName" name="FName" id="FName" value="" /> <form:input path="person.LName" name="LName" id="LName" value="" /> </c:forEach> <button type="submit"></button> </form:form> When I click on the submit button I want to bind the Person List to the POST method on the controller.. @RequestMapping(value = { "savePerson" }, method = RequestMethod.POST) public String savePerson(Model model, HttpServletRequest request, HttpSession session,@ModelAttribute("persons")List<Person> persons) { System.out.println(persons.length); return "success"; } but the persons list is not binding/fetching at the POST method. Is it possible to bind a list objects in this way or is there an alternative for this?
Tags (comma-separated)
Save Edits
Cancel