Hey Fabian,
I just figured this out yesterday myself. Your code is correct, but the next step is how you write your jsp and your controller. Here is an example of the jsp code for populating a drop-down with the list. It assumes that your companyManager manages company domain objects that have an id property, and a name property:
Code:
<B>Company:</B>
<spring:bind path="command.company">
<FONT color="red">
<B><c:out value="${status.errorMessage}"/></B>
</FONT>
<SELECT name="companyId">
<c:forEach var="company" items="${listCompany}">
<c:if test="${command.company.id == company.id}">
<OPTION selected="<c:out value="${command.company.id}"/>" value="<c:out value="${company.id}"/>"><c:out value="${company.name}"/></OPTION>
</c:if>
<c:if test="${command.company.id != company.id}">
<OPTION value="<c:out value="${company.id}"/>"><c:out value="${company.name}"/></OPTION>
</c:if>
</c:forEach>
</SELECT>
</spring:bind>
The next thing to do, in order to make sure the selections "stick", is to add the following to your controller. This example assumes you are assigning the Company to an employee, and that your companyManager can get Company objects from an Id:
Code:
protected void onBindAndValidate(HttpServletRequest request, Object command, BindException errors) {
Employee employee = (Employee) command;
long companyId = Long.parseLong(request.getParameter("companyId"));
Company company = companyManager.getCompany(companyId);
employee.setCompany(company);
}
You would need to modify this to your own needs, but the onBindAndValidate will then set your Domain Object's company to the selection from your jsp.
I hope that helps.
Take care,
James