I have a method like this:
public boolean validateMessage(String message, Errors errors) {
if (!StringUtils.hasLength(message)) {
errors.rejectValue(wrapperName + "message", "EMPTY_MESSAGE", EMPTY_MESSAGE_ERRORMSG) ;
return false ;
}
return true ;
}
I want to call this method with a new Errors object, like:
boolean result = validateMessage("hi", new Errors()) ;
However, this kind of instantiation is not allowed for Errors. Please advice.
If not with Errors, can I achieve this using an empty (new) BindingResult
ErrorsandBindingResultare interfaces, therefore they cannot be instantiated. Your only option would be to use one of the classes which implementsErrors.You could use
org.springframework.validation.BindException, this implementsErrors– see here for details.