Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>*I'm using <a href="http://docs.jboss.org/hibernate/validator/5.1/reference/en-US/html_single/" rel="nofollow noreferrer">Hibernate Validator APIs</a> to validate my beans. To preserve form data along with displaying error messages, you need to do these 3 things:</p> <ol> <li>Annotate your bean (eg. @NotEmpty, @Pattern, @Length, @Email etc.)</li> </ol> <p><img src="https://i.stack.imgur.com/spEsB.png" alt="enter image description here"></p> <ol start="2"> <li><p>Inside controller:</p> <p>@Controller public class RegistrationController {</p> <pre><code>@Autowired private RegistrationService registrationService; @RequestMapping(value="register.htm", method=RequestMethod.GET, params="new") public String showRegistrationForm(Model model) { if (!model.containsAttribute("employee")) { model.addAttribute("employee", new Employee()); } return "form/registration"; } @RequestMapping(value="register.htm", method=RequestMethod.POST) public String register(@Valid @ModelAttribute("employee") Employee employee, BindingResult bindingResult, RedirectAttributes redirectAttributes) { if (bindingResult.hasErrors()) { redirectAttributes.addFlashAttribute("org.springframework.validation.BindingResult.employee", bindingResult); redirectAttributes.addFlashAttribute("employee", employee); return "redirect:register.htm?new"; } registrationService.save(employee); return "workspace"; } // .... </code></pre> <p>}</p></li> <li><p>Update your view/jsp to hold error messages:</p></li> </ol> <p><img src="https://i.stack.imgur.com/Ku0kS.png" alt="enter image description here"></p> <p>This <a href="http://gerrydevstory.com/2013/07/11/preserving-validation-error-messages-on-spring-mvc-form-post-redirect-get/*" rel="nofollow noreferrer">article</a> can surely be helpful.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload