Skip to content

Instantly share code, notes, and snippets.

@pohy
Created Nov 26, 2015
Embed
What would you like to do?
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