Announcement Announcement Module
Collapse
No announcement yet.
Using @Valid and @RequestBody on Controller method Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Using @Valid and @RequestBody on Controller method

    I'm attempting to build out some controller endpoints that will be accessed via Ajax. I'm trying to do the following:

    Code:
    @RequestMapping(value = "/form", method = RequestMethod.POST)
    public @ResponseBody ModelMap form(@Valid @RequestBody MyCommandObject obj, BindingResult result) {
    ...
    }
    However, when I access this controller, I get the following error:
    Code:
    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:327)
    	at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:171)
    Used independently the @Valid/@ResponseBody annotations work just fine for me. It seems that using them together causes some problems.
    Is the combined use of @Valid and @RequestBody not supported? If not, what's the recommended method for easily validating Ajax/JSON submitted client data?

    Thanks.

  • #2
    This is reported as an improvement here:

    https://jira.springframework.org/browse/SPR-6709

    I'm also thinking a way of doing this.

    Comment

    Working...
    X