Spring MVC Form Validation Custom Error with Parameters/Tokens/Arguments -
my spring mvc form validation working, how expand parameters or "tokens" in .properties file?
e.g.: messages.properties
error.field.required=<b><a>{0}</a></b> required
spring mvc validator class adds error/code:
@component public class mymodelvalidator implements validator { @override public boolean supports(class<?> clazz) { return mymodel.class.equals(clazz); } @override public void validate(object target, errors errors) { mymodel mymodel = (mymodel)target; validationutils.rejectifempty(errors, "address.addressline1", "error.field.required"); } }
i need pass in custom string, such "address line 1" replace {0} token description.
you can pass values message placeholders using errorargs
parameter of rejectifempty
method.
validationutils.rejectifempty(errors, "address.addressline1", "error.field.required", new object[] { "value 1st placeholder", "value 2nd placeholder" });
Comments
Post a Comment