开发者

Spring MVC: BindingResult allegedly declared without preceding model attribute

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 {开发者_Go百科
    @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.


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) {
    ...
}


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)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜