I have not been able to find a solution on this yet after searching and searching.
Using Spring 3.1
I have a form where I would like the user to be able to add multiple point of contacts (poc). In my JSP I have a submit button for adding a poc. It goes to a Spring Controller, gets the current list of pocs from the domain object (which will be empty at first), adds the poc to the list and then puts the domain object back into the model before returning to the same view. Then the user will ultimately submit the entire page which will go to the controller and save the entire object to persistence.
I have tried various attempts and come up with different results from only being able to add one poc with a new one overwriting the existing, to not being able to get the entered poc displayed on the form. I will put the code I currently have.
JSP:
Spring Controller:Code:<form:form method="post" commandName="request"> ... <h2>POC:</h2> <input type="text" name="newPoc"/> <input type="submit" name="addPoc" value="Add POC"/> <table> ... <c:forEach items="${request.pointOfContacts}" var="poc" varStatus="vs"> <tr> <td><form:label path="pointOfContacts[${vs.index}].name/></td> ..... </c:forEach> ...... </table> </form:form>
Domain ObjectsCode:@RequestMapping(value="/request", method=RequestMethod.POST, param="addPoc") public Sring addPoc(@RequestParam String newPoc, MyRequest req, Model model) { PointOfContact poc = new PointOfContact(); poc.setName(newPoc); List<PointOfContact> pocs = req.getPointOfContacts(); pocs.add(poc); req.setPointOfContacts(pocs); model.addAttribute("request", req); return "requestForm"; }
Does anybody have any solutions? I have seen various posts about AutoPopulatingList, is this a solution? If so how would I use it in this example.Code:@Entity public class MyRequest { ... @OneToMany(Cascade=CascadeType.ALL) private List<PointOfContact> pointOfContacts = new ArrayList<PointOfContact>(); ..... } @Entity public class PointOfContact { ... private String name; .... }


Reply With Quote
