Skip to content

Instantly share code, notes, and snippets.

@pohy
Created November 26, 2015 14:38
Show Gist options
  • Save pohy/4e06e4a69536d6a3dc53 to your computer and use it in GitHub Desktop.
Save pohy/4e06e4a69536d6a3dc53 to your computer and use it in GitHub Desktop.
public ValidationResponse createValidationResponse(BindingResult result, boolean translate) {
ValidationResponse response = new ValidationResponse();
if(!result.hasErrors()) {
response.setSuccess(true);
return response;
}
response.setSuccess(false);
Locale locale = LocaleContextHolder.getLocale();
for (FieldError error : result.getFieldErrors()) {
String message = translate ? messageSource.getMessage(error, locale) : error.getCode();
response.addError(error.getField(), message);
}
return response;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment