validation - Spring - Populate form field with error message -
I have a Spring 2.5 application and I have many forms where I perform various verification. I have no problem completing this recognition and displaying errors on the page next to the appropriate form input. I was thinking that I can put the error message in the form value instead, so that it is just And
do this way
inside your valid method
< Pre> import static org.springframework.validation.BindingResult.MODEL_KEY_PREFIX; Validate public null (object command, mistake errors) {/ ** * Keep in mind that the characteristic of my model is called command-override, if necessary / user user = (user) ((bindingring errors)) Get .getModel (). (MODEL_KEY_PREFIX + "command"); User.setUserName ("You must provide a username"); / ** * Now just do it / / (errors in binding result) .getModel (). Put (MODEL_KEY_PREFIX + "command", user); }
This will satisfy your needs
WARNING: Message error is a plain string, You can not set some assets whose class is not a plain Is string
Comments
Post a Comment