Take a look at my solution:
public class CompanyIdToInstanceConverter implements Converter<String, Company> { @Autowired CompanyService _companyService; @Override public Company convert(final String companyIdStr) { return _companyService.find(Long.valueOf(companyIdStr)); } }
This converts the company identifier from the selected one to the company, receiving it from the database.
If you have additional questions, ask, because now I am doing similar things in my application :)
In addition, you need to add in the app-context:
<mvc:annotation-driven conversion-service="conversionService" /> <bean id="conversionService" class="org.springframework.format.support.FormattingConversionServiceFactoryBean"> <property name="converters"> <set>toryLabelConverter"></bean> <bean class="pl.greenpath.converter.CompanyIdToInstanceConverter"></bean> </set> </property> </bean>
source share