2 form on the same page with Spring mvc, Thymeleaf, does anyone know how?

0

This registration form for Physician, so I created this modal for the user to register specialties.

@GetMapping("/cadastro")
public ModelAndView preSalvar(@ModelAttribute("medico") Medico medico,@ModelAttribute Especialidade especialidade){
    return new ModelAndView("home","conteudo","medico/add");
}

I added the @ModelAttribute of the specialty, and the specialty form with th: object="$ {specialty}", but is giving this exception: java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'specialty' available as request attribute

Has anyone ever done anything like this?

    
asked by anonymous 03.12.2018 / 01:37

1 answer

0

Friend, I believe the above error is because you did not put in the @ModelAttribute the name of the object you are referring to and that is in the view. Try this:

@GetMapping("/cadastro")
public ModelAndView preSalvar(@ModelAttribute("medico") Medico medico, @ModelAttribute("especialidade") Especialidade especialidade){
    return new ModelAndView("home","conteudo","medico/add");
}
    
07.12.2018 / 20:46