I am new to Spring MVC. I am writing an app that uses Spring, Spring MVC and JPA/Hibernate I don\'t know how to make Spring MVC set a value coming from a dropdown into a mod
The trick as you have already noted is to register a custom converter which will convert the id from the drop down into a Custom instance.
You can write a custom converter this way:
public class IdToCustomerConverter implements Converter{
@Autowired CustomerRepository customerRepository;
public Customer convert(String id) {
return this.customerRepository.findOne(Long.valueOf(id));
}
}
Now register this converter with Spring MVC: