0
votes

I am experiencing a very peculiar behavior with Spring MVC 3.1.0.M2 that suddenly popped out:

@Controller
@RequestMapping("/admin/participants/{participantId}")
public class ParticipantEditController extends ParticipantControllerSupport {
    @ModelAttribute("participant")
    public Participant getParticipant(
        @PathVariable("participantId") final long participantId) {
        // ...
    }

    @RequestMapping(value = "/{tab}/edit", method = RequestMethod.PUT)
    public ModelAndView save(
        @ModelAttribute("participant") final Participant participant,
        final BindingResult errors) {
        // ...
    }
}

When I'm submitting my form I get the following exception:

java.lang.IllegalStateException: Errors/BindingResult argument declared without preceding model attribute. Check your handler method signature!
    at org.springframework.web.method.annotation.support.ErrorsMethodArgumentResolver.resolveArgument(ErrorsMethodArgumentResolver.java:60)
    at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:65)
    ...

What's troubling me is that my BindingResult does immediately follow the model attribute in the method signature.

I've tried it with and without a @Valid annotation and with more or less other parameters, to no avail.

Does anyone know what I'm doing wrong? Any help greatly appreciated.

2
This may be a bug in the ErrorsMethodArgumentResolver (or a releated class). Consider reporting it to the spring team. 3.1.0.M2 is still a development release; it may be a good idea to get 3.0.6 (the latest ga release) and see if you can reproduce the error. - DwB
I have submitted this topic to the Spring community forums: forum.springsource.org/… - Philipp Jardas

2 Answers

2
votes

I have found the problem. The culprit was another method in a parent class that used a ' @ModelAttribute to calculate another model attribute:

@ModelAttribute("foobar")
public String getFoobar(@ModelAttribute("participant") Participant participant) {
    ...
}
0
votes

I hope this is not the correct answer. Try not declaring your parameters as final. ex.

public ModelAndView save(
    @ModelAttribute("participant") Participant participant,
    BindingResult errors)