I'm using spring mvc 3.1.0 with jsp/jstl. To submit object to my controller I'm using the ModelAttribute annotation and all is working fine. But, when I try to submit a complex object to my controller his value is null. This is my object model:
UorgVO.java
public class UorgVO { private String nom; private String nomAbrege; private UorgVO refUniteOrganisParent; //getters&Setters.. } and there is my jsp page:
<form:form method="post" action="saveUorg.html" modelAttribute="uorg" > <table> <tr> <th>Nom</th> <th>Nom abregé</th> <th>Unité père</th> </tr> <tr> <td><input type="text" path="nom" name="nom"/></td> <td><input type="text" path="nomAbrege" name="nomAbrege"/></td> <td> <select id="refUniteOrganisParent" name="refUniteOrganisParent" path="refUniteOrganisParent"> <option value="null"> --- </option> <c:forEach items="${listeuos}" var="uorgg" varStatus="status" > <option value="${uorgg}">${uorgg} </option> </c:forEach> </select> </td> </tr> </table> <input type="submit" value="Enregistrer uorg"/> </form:form> And my controller is:
@RequestMapping(value ="/saveUorg", method = RequestMethod.POST) public ModelAndView saveUorg(@ModelAttribute("uorg") UorgVO uorg,BindingResult result) { System.out.println("My foreign attribute is:" +uorg.getRefUniteOrganisParent()); return new ModelAndView("uorg_recherche"); } And the printed value is null, but the other attributes of my object are submitted.
Thank's in advance for help
<input type="submit" value="Enregistrer uorg" <BQ>you don't close the input tag, and the<BQ>tag looks like it shouldn't be there.refUniteOrganisParent=valueparameter when you submit? Also, you won't be able to bind this value directly to aUorgVO- because the transmitted value will be a string. You'll need to register aPropertyEditorin the controller which will convert the transmitted string to aUorgVO. See this example