I have a simple form that has a select box populated by the database. When validation is triggered the select box is empty. I'm new to spring and I seem to be missing something.
Any help is appreciated? Thanks in advance.
In the controller below sites is the dynamic content.
@RequestMapping("/registration/registration.html")
public ModelMap setupRegistrationForm(HttpServletRequest request, RegistrationForm form) {
ModelMap map = new ModelMap();
I18NSite[] sites = new Sites().getSites();
map.put("sites", sites);
return map;
}
@RequestMapping(value="/registration/registration.html", method = RequestMethod.POST)
public String saveRegistrationForm(HttpServletRequest request,RegistrationForm form, BindingResult errors) {
I18NSite site = Sites.getSite();
RegistrationFormValidator validator = new RegistrationFormValidator();
validator.setDataSource(site.getDataSource());
validator.validate(form,errors);
if (errors.hasErrors()) {
return "registration/registration";
} else {
// other code
}
return "redirect:/index.html";
}