I need help. I am beginner in jsp, MVC. I want to validate form input with custom validator in Spring 3 MVC.
My validator class
package validator
This happens because of mismatch between default model attribute names in view and controller:
<form:form>
without modelAttribute
(or commandName
) attribute, it uses default model attribute name command
.@ModelAttribute UserModel user
in your controller, it assumes that the name of this attribute is a decapitalized class name, i.e. userModel
.That is, error messages produced by validator are bound to model attribute named userModel
, while your view tries to show errors for model attribute command
.
You need to set a model attribute name explicitly, either in the view (<form:form modelAttribute = "userModel" ...>
) or in the controller (@ModelAttribute("command")
).