I have been trying for the last 3 days, but I can not solve my problem.
I have a Person class
@SuppressWarnings("rawtypes") @OneToMany(cascade = CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="person") @JoinColumn(name="person_id") public Set<Book> books = new HashSet<Book>(); class Book book_id person_id
In my JSP form, I have
<c:forEach items="${BookList}" var="var1" varStatus="counter"> <input type="checkbox" name="books[${counter.index}].book_id" value="${var1.book_id}" >${var1.book_name}</input> </c:forEach>
I insert books into the table depending on the checkboxes. The list of books is populated using the refrenceData model.
CONTROLLER
@RequestMapping(value = "/persons/add", method = RequestMethod.GET) public String getAdd(Model model) { logger.debug("Received request to show add page"); // Create new Person and add to model // This is the formBackingOBject model.addAttribute("personAttribute", new Person()); // This will resolve to /WEB-INF/jsp/addpage.jsp return "hibernate/addpage"; } @RequestMapping(value = "/persons/add", method = RequestMethod.POST) public String add(@Valid @ModelAttribute("personAttribute") Person person, BindingResult result) { logger.debug("Received request to add new person"); if (result.hasErrors()) return "hibernate/addpage"; else personService.add(person); // This will resolve to /WEB-INF/jsp/addedpage.jsp return "hibernate/addedpage"; }
Now, if I have one Book object, then it works fine, and the data is entered into the database, but if I installed it, then it speaks of an invalid property book [1]
After a lot of searching on SO and Google I leart, I have two options
PropertyEditor AutoPopulatingList
I do not know how to use them in my case. Can someone help me, where should I use them and how to use it?
John
source share