Skip to content

Instantly share code, notes, and snippets.

@darbyluv2code
Created August 31, 2019 13:54
Show Gist options
  • Save darbyluv2code/e1e27b2178fd25aa8e224270a2b0d70f to your computer and use it in GitHub Desktop.
Save darbyluv2code/e1e27b2178fd25aa8e224270a2b0d70f to your computer and use it in GitHub Desktop.
Spring MVC Form Validation - with custom model attributes
@RequestMapping("/processForm")
public String processForm(@Valid @ModelAttribute("student") Student theStudent, BindingResult result, Model model) {
if(result.hasErrors()) {
// add the country options to the model
model.addAttribute("theCountryOptions", countryOptions);
// add the favorite Language options to the model
model.addAttribute("favoriteLanguageOptions", favoriteLanguageOptions);
// add the favorite Os options to the model
model.addAttribute("favoriteOsOptions", favoriteOsOptions);
return "student-form";
}
return "student-confirmation";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment