Meu projeto tem duas classes principais: hospede e reserva, cada uma com seu respectivo validator. No controller de hospedes tenho um método que redireciona para uma página de exibição de reservas:
@GetMapping("reservas/{id_hospede}")
public ModelAndView reservas(@PathVariable(value = "id_hospede") Integer id, RedirectAttributes redirectAttributes) {
ModelAndView modelAndView = new ModelAndView("redirect:../../reservas/reservas");
Hospede hospede = this.hospedeService.consultar(id);
redirectAttributes.addFlashAttribute("hospede", hospede);
return modelAndView;
}
no controller de reservas:
@GetMapping("reservas")
public ModelAndView reservas(Hospede hospede) {
ModelAndView modelAndView = new ModelAndView("reservas/reservas");
modelAndView.addObject("hospede",hospede);
return modelAndView;
}
tenho uma jsp que chama o método no controller de hospedes que redireciona a requisição para o controller de reservas a fim de listar todas as reservas deste hóspede, mas sempre obtenho o erro:
java.lang.IllegalStateException: Invalid target for Validator [br.com.ehospedagem.reservas.validation.ReservaValidation@1134762f]: Zequinha,60000000000,98999999999,zequinha@teste.com.br
org.springframework.validation.DataBinder.assertValidators(DataBinder.java:542)
org.springframework.validation.DataBinder.addValidators(DataBinder.java:553)
br.com.ehospedagem.reservas.controller.ReservaController.initBinder(ReservaController.java:42)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:220)
org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:134)
org.springframework.web.method.annotation.InitBinderDataBinderFactory.initBinder(InitBinderDataBinderFactory.java:62)
org.springframework.web.bind.support.DefaultDataBinderFactory.createBinder(DefaultDataBinderFactory.java:57)
org.springframework.web.method.annotation.ModelAttributeMethodProcessor.resolveArgument(ModelAttributeMethodProcessor.java:111)
org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:121)
org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:160)
org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:129)
org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:116)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738)
org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
javax.servlet.http.HttpServlet.service(HttpServlet.java:634)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
esse problema só ocorre quando adiciono o objeto hospede ao modelandview de reservas, se eu tentar adicionar uma string por exemplo, o erro não acontece:
@GetMapping("reservas")
public ModelAndView reservas(Hospede hospede) {
ModelAndView modelAndView = new ModelAndView("reservas/reservas");
modelAndView.addObject("hospede",hospede); //erro nesse linha
return modelAndView;
}