1
votes

I have this controller, But i don't know why when I access to /accounts/manageaccount.do I got an error

public class ManageAccountController {

    public static final Logger LOGGER = Logger.getLogger    (ManageAccountController.class);        

    /**
     * 
     * @param request the http servlet request.
     * @param model the spring model.
     * 
     */ 
    @RequestMapping(value = "/accounts/manageaccount.do", method = RequestMethod.GET)
    public String showForm( @ModelAttribute("dataAccountCommand") final DataAccountCommand dataAccountCommand,
                            HttpServletRequest request, 
                            BindingResult result, 
                            Model model, 
                            Locale locale) {                            
        return "SHOW_VIEW";
    }       

Exception: org.springframework.web.bind.annotation.support.HandlerMethodInvocationException: Failed to invoke handler method [public java.lang.String fr.telecom.controller.accounts.ManageAccountController.showForm(fr.telecom.domain.formBeans.DataAccountCommand,javax.servlet.http.HttpServletRequest,org.springframework.validation.BindingResult,org.springframework.ui.Model,java.util.Locale)]; nested exception is java.lang.IllegalStateException: Errors/BindingResult argument declared without preceding model attribute. Check your handler method signature!

1

1 Answers

5
votes

You need to place the BindingResult parameter directly after the parameter that is annotated with @ModelAttribute. So changing your signature to:

@RequestMapping(value = "/accounts/manageaccount.do", method = RequestMethod.GET)
    public String showForm( 
       @ModelAttribute("dataAccountCommand") final DataAccountCommand dataAccountCommand,  
       BindingResult result,       // moved up!                         
       HttpServletRequest request, 
       Model model, 
       Locale locale) {

        return "SHOW_VIEW";
    }

should do the trick.

See also: http://viralpatel.net/blogs/errorsbindingresult-argument-declared-without-preceding-model-attribute/