2

I upgraded to Spring 3.1.1.RELEASE, and now I'm getting an exception on the following method:

@RequestMapping(method = RequestMethod.POST, params = "_finish")
public ModelAndView doPostFinish(@PathVariable("runEnvironmentName") RunEnvironment pEnvironment, @ModelAttribute("command") JobSpecNewCommand pCommand, BindingResult pErrors) 
{
...
}

Throws the following exception:

java.lang.IllegalStateException: An Errors/BindingResult argument is expected 
to be immediately after the model attribute argument in the controller method 
signature: 

java.lang.IllegalStateException: An Errors/BindingResult argument is expected to be immediately after the model attribute argument in the controller method signature: public org.springframework.web.servlet.ModelAndView de.wwag.infra.oocsd.projectAdmin.fe.natures.hudson.jobspecs.RunEnvJobSpecNewController.doPostFinish(de.wwag.infra.oocsd.projectAdmin.common.domain.RunEnvironment,de.wwag.infra.oocsd.projectAdmin.fe.natures.hudson.jobspecs.JobSpecNewCommand,org.springframework.validation.BindingResult)
    at org.springframework.web.method.annotation.ErrorsMethodArgumentResolver.resolveArgument(ErrorsMethodArgumentResolver.java:62) ...


As you can see the method signature is as expected. The BindingResult argument is declared after the model attribute.

In the same class the following method is declared:

@ModelAttribute("otherJobSpecs")
public List<JobReference> modelOtherJobSpecs(@PathVariable("runEnvironmentName") RunEnvironment pEnvironment, @ModelAttribute("command") JobSpecNewCommand pCommand) 
{
...
}

When I remove the method from the class, everything works as expected.

Any ideas?

skaffman
  • 398,947
  • 96
  • 818
  • 769
smith
  • 23
  • 1
  • 4

2 Answers2

1

It's a bug in Spring, I reported it: SPR-9378.

axtavt
  • 239,438
  • 41
  • 511
  • 482
0

Reading the Spring bug SPR-9378, you must remove the model variable from the @ModelAttribute method:

@ModelAttribute
public void populateModel(Model model) { //this method haven't Libro Object
    model.addAttribute(Genero.values());
    model.addAttribute(EstadoLibro.values());
}

@RequestMapping(method=RequestMethod.POST)
public String grabarLibro(@Validated @ModelAttribute Libro libro, BindingResult result) {
   ...
}

It worked for me.

ajaristi
  • 979
  • 1
  • 9
  • 16