Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Solution for java.lang.IllegalStateException

    • 0
    • 1
    • 1
    • 2
    • 0
    • 0
    • 0
    • 0
    • 1.12k
    Comment on it

    Hello friends, sometimes you come across with this very unexpected exception.

    For eg: In the given code, after execution this exception occurs..

    @RequestMapping(value = "addUser")
        public String addUser(@ModelAttribute("userForm") UserForm userForm,
                ModelMap map, BindingResult results) {
    
            if (results.hasErrors()) {
                return "add_user_form";
            }
    
            return "add_user_success";
        }
    //...
    }

    Exception: java.lang.IllegalStateException: Errors/BindingResult argument declared without preceding model attribute.

    Solution: Well basically, Spring expects the BindingResult attribute to be present right after your Model attribute. So if we change the above controller method to:

    RequestMapping(value = "addUser")
    public String addUser(@ModelAttribute("userForm") UserForm userForm,
            BindingResult results, ModelMap map) 

    This will solve the error.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: