Talk about beauty? Well, I started to study Spring
for Algaworks courses recently and today I came across a problem, it is the following:
I have a form that shows me a list of employees, and how it was passed in the course, I also have a registration and editing form that is the same. Dai thought of doing a modal that would serve as a registration and editing form, so I tried to do it and I found it, the modal is working 90%, the validations are being done in JQuery
, registering, showing success message and everything , but here comes the problem.
I do not know if you know how to validate the server with Spring
, the course taught us to do so:
@RequestMapping(value="/novo", method = RequestMethod.POST)
public String salva(@Validated Funcionario funcionario, Errors errors, RedirectAttributes attributes){
if (errors.hasErrors()) {
return "redirect:/saboia/funcionarios";
}else{
funcionarios.save(funcionario);
attributes.addFlashAttribute("mensagem","Funcionario Salvo com Sucesso!");
return "redirect:/saboia/funcionarios";
}
}
That is, if the form has errors like it is being shown there in the first if, then I would give a redirect to the specified controller, however, the redirect would terminate the registration request, so all data would be lost. / p>
As the registration form is no longer a page specifies how it was before so I could give a redirect so I was kind of lost, How do I make the server validations come up to my modal?