Created
August 31, 2019 13:54
-
-
Save darbyluv2code/e1e27b2178fd25aa8e224270a2b0d70f to your computer and use it in GitHub Desktop.
Spring MVC Form Validation - with custom model attributes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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