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

error path = "*" cssClass = "error" & gt; Can be displayed in the input field instead of Tags I tried to set the value in Valuerator class and I think it is set to Long while setting in session, but the value does not appear on the page in the field is. For example, I have a control page such as:

  & lt; Form: input path = "user name" cssClass = "textinput" cssErrorClass = "textinput-error" /> In the validator, I tried to set the user name in the object:  
  Validation High .rejectIfEmptyOrWhitespace (errors, "user name", "error. Field -required "); // This value does not appear on the page user.setUsername ("You must provide a username");  

Is it possible to set an error based value and is it populated on the page?

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

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -