Ana
Aug 25th, 2005, 10:50 AM
Hello,
Is there maybe some better practice for binding nested objects when using spring binding and Form Controllers than the one suggested in the code bellow:
e.g.situation: A Student holds reference to a nested object of class University, and both Student and University map to their own tables in DB:
form:
<select name="universityId">
<c:forEach var="university" items="${universityList}">
<option value="<c:out value="${university.id}"/>"
<c:if test="${not empty student.university.id}">
<c:if test="${student.university.id == university.id}">selected="selected"</c:if>
</c:if>
>
<c:out value="${university.name}"/>
</option>
</c:forEach>
</select>
FormController - onBindandValidate:
String universityId = request.getParameter("universityId");
if (universityId!= null && !universityId.equals("")) {
University university = universityManager.getUniversity(universityId);
user.setUniversity(university);
}
Tnx in advance for the recommendation!
Is there maybe some better practice for binding nested objects when using spring binding and Form Controllers than the one suggested in the code bellow:
e.g.situation: A Student holds reference to a nested object of class University, and both Student and University map to their own tables in DB:
form:
<select name="universityId">
<c:forEach var="university" items="${universityList}">
<option value="<c:out value="${university.id}"/>"
<c:if test="${not empty student.university.id}">
<c:if test="${student.university.id == university.id}">selected="selected"</c:if>
</c:if>
>
<c:out value="${university.name}"/>
</option>
</c:forEach>
</select>
FormController - onBindandValidate:
String universityId = request.getParameter("universityId");
if (universityId!= null && !universityId.equals("")) {
University university = universityManager.getUniversity(universityId);
user.setUniversity(university);
}
Tnx in advance for the recommendation!