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

Asked

Viewed 323 times

0

This Physician registration screen, then 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 @Modelattribute from 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

inserir a descrição da imagem aqui

Someone has done something similar?

  • The exception is when I click to register in the doctor’s form

  • I believe that the most correct approach would be to separate in two Forms: one for the main page and the other for the modal.

1 answer

0

Friend, I believe the error referred to is that you have not put in @Modelattribute the name of the object to which you refer and which is in the view. Test this:

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.