Reputation: 59
im using spring mvc 3.1.0 with jsp/jstl Please, how to use conversion with @ModelAttribute in spring mvc
i want to submit an object from my jsp page to the controller, my object contains a select tag of an object field in my class who is always submitted with null value.
there my object:
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" <BQ> <a href="recherche_uorg.html"> Annuler</a>
</form:form>
and my controller is:
@RequestMapping(value ="/saveUorg", method = RequestMethod.POST)
public ModelAndView saveUorg(@ModelAttribute("uorg") UorgVO uorg,BindingResult result){
System.out.println("contenu du nom de l'UO est :" +uorg.getRefUniteOrganisParent());
return new ModelAndView("uorg_recherche");
}
and the printed value is null
Thank's in advance for help
Upvotes: 0
Views: 2259
Reputation: 7238
I guess you won't be able to bind nested objects with these forms. What you may want to look in to is Spring Binding Form. Refer here
Upvotes: 0