-
Notifications
You must be signed in to change notification settings - Fork 38.7k
Closed
Labels
has: votes-jiraIssues migrated from JIRA with more than 10 votes at the time of importIssues migrated from JIRA with more than 10 votes at the time of importin: webIssues in web modules (web, webmvc, webflux, websocket)Issues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancementA general enhancement
Milestone
Description
Nick Padgett opened SPR-7114 and commented
Instead of using a command/form object, I bind much of my data to the request body. I expected that I could specify an Errors/BindingResult object after a @RequestBody
method parameter. Currently, I do the following:
@RequestMapping(value = "/events", method = RequestMethod.POST)
public String create(@RequestBody final Event event,
final HttpServletResponse response, final Model model)
throws BindException {
final BindingResult result = new BeanPropertyBindingResult(event, "");
ValidationUtils.invokeValidator(this.eventValidator, event, result);
if (result.hasErrors()) {
throw new BindException(result);
}
...
}
I would like to do the following:
@RequestMapping(value = "/events", method = RequestMethod.POST)
public String create(@RequestBody final Event event,
final BindingResult result, final HttpServletResponse response,
final Model model) throws BindException {
ValidationUtils.invokeValidator(this.eventValidator, event, result);
if (result.hasErrors()) {
throw new BindException(result);
}
...
}
However, when I do, I receive the following exception:
2010-04-21 09:48:09,014 [http-8080-2] WARN org.springframework.web.servlet.handler.SimpleMappingExceptionResolver - Handler execution resulted in exception
org.springframework.web.bind.annotation.support.HandlerMethodInvocationException: Failed to invoke handler method [public java.lang.String com.playonsports.event.controller.EventController.create(com.playonsports.event.bean.Event,org.springframework.validation.BindingResult,javax.servlet.http.HttpServletResponse,org.springframework.ui.Model) throws org.springframework.validation.BindException]; nested exception is java.lang.IllegalStateException: Errors/BindingResult argument declared without preceding model attribute. Check your handler method signature!
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:171)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:414)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:402)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:771)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
...
Caused by: java.lang.IllegalStateException: Errors/BindingResult argument declared without preceding model attribute. Check your handler method signature!
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.resolveHandlerArguments(HandlerMethodInvoker.java:264)
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:163)
... 54 more
Affects: 3.0.2
Attachments:
- HandlerMethodInvoker.java (35.20 kB)
11 votes, 13 watchers
Metadata
Metadata
Assignees
Labels
has: votes-jiraIssues migrated from JIRA with more than 10 votes at the time of importIssues migrated from JIRA with more than 10 votes at the time of importin: webIssues in web modules (web, webmvc, webflux, websocket)Issues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancementA general enhancement