List of usage examples for org.springframework.validation FieldError getDefaultMessage
@Override
@Nullable
public String getDefaultMessage()
From source file:com.google.ie.dto.ViewStatus.java
/** * @param errors/* w w w .jav a 2 s .c o m*/ */ public static ViewStatus createErrorViewStatus(BindingResult errors) { ViewStatus viewStatus = new ViewStatus(); log.warn("Idea object has " + errors.getErrorCount() + " validation errors"); viewStatus.setStatus(WebConstants.ERROR); for (Iterator<FieldError> iterator = errors.getFieldErrors().iterator(); iterator.hasNext();) { FieldError fieldError = iterator.next(); viewStatus.addMessage(fieldError.getField(), fieldError.getDefaultMessage()); log.warn("Error found in field: " + fieldError.getField() + " Message :" + fieldError.getDefaultMessage()); } return viewStatus; }
From source file:com.google.ie.dto.ViewStatus.java
/** * @param errors//from w ww . j a va 2 s . c o m */ public static ViewStatus createProjectErrorViewStatus(BindingResult errors) { ViewStatus viewStatus = new ViewStatus(); log.warn("Project object has " + errors.getErrorCount() + " validation errors"); viewStatus.setStatus(WebConstants.ERROR); for (Iterator<ObjectError> iterator = errors.getAllErrors().iterator(); iterator.hasNext();) { ObjectError objError = iterator.next(); if (objError instanceof FieldError) { FieldError fieldError = (FieldError) objError; viewStatus.addMessage(WebConstants.ERROR, fieldError.getField() + " - " + fieldError.getDefaultMessage()); log.warn("Error found in field: " + fieldError.getField() + " Message :" + objError.getDefaultMessage()); } else { viewStatus.addMessage(WebConstants.ERROR, objError.getDefaultMessage()); log.warn(" Message :" + objError.getDefaultMessage()); } } return viewStatus; }
From source file:jetx.ext.springmvc.SpringMvcFunctions.java
/** * ??//from w ww . ja va2 s . co m */ public static List<String> fieldErrors(JetPageContext ctx, String fieldName) { Errors errors = FunctionUtils.findErrors(ctx.getContext()); if (errors == null) { return EMPTY_STRING_LIST; } List<FieldError> fes = errors.getFieldErrors(fieldName); List<String> msgs = new ArrayList<String>(0); for (FieldError fe : fes) { String[] codes = fe.getCodes(); String defaultMsg = fe.getDefaultMessage(); Object[] args = fe.getArguments(); Locale locale = getLocale(ctx); MessageSource ms = getMessageSource(ctx); if (codes == null || codes.length == 0 || ms == null) { msgs.add(defaultMsg); } else { String msg = null; for (int i = 0; i < codes.length; i++) { try { msg = ms.getMessage(codes[i], args, locale); } catch (NoSuchMessageException e) { // } if (msg == null) { msg = defaultMsg; } } msgs.add(msg); } } return Collections.unmodifiableList(msgs); }
From source file:org.zht.framework.validate.ValidateHandler.java
public static String getDefaultError(BindingResult result) { if (result.hasErrors()) { List<FieldError> fieldEist = result.getFieldErrors(); if (fieldEist != null && fieldEist.size() > 0) { FieldError fieldError = fieldEist.get(0); fieldError.getCode();/* w w w . j a v a 2s . c om*/ String prefix = "\r\n" + "???"; String value = "{" + (fieldError.getRejectedValue() == null ? " " : fieldError.getRejectedValue()) + "}"; String message = "" + fieldError.getDefaultMessage(); return prefix + "" + value + "\r\n" + message; } else { List<ObjectError> allErrorlist = result.getAllErrors(); ObjectError oe = allErrorlist.get(0); return "" + oe.getDefaultMessage(); } } else { return null; } }
From source file:org.haftrust.verifier.validator.BankValidatorTestBase.java
protected void assertErrorContainingMessage(final String errorMessage) { assertThat(errors.getErrorCount(), greaterThanOrEqualTo(1)); FieldError error = errors.getFieldError(); assertThat(error.getDefaultMessage(), containsString(errorMessage)); }
From source file:com.tsguild.dolphinblog.controller.RestValidationHandler.java
@ExceptionHandler(MethodArgumentNotValidException.class) @ResponseBody//from w w w .ja v a 2s .c o m @ResponseStatus(HttpStatus.BAD_REQUEST) public ValidationErrorContainer processValidationErrors(MethodArgumentNotValidException e) { BindingResult result = e.getBindingResult(); List<FieldError> fieldErrors = result.getFieldErrors(); ValidationErrorContainer errors = new ValidationErrorContainer(); for (FieldError fError : fieldErrors) { errors.addValidationError(fError.getField(), fError.getDefaultMessage()); } return errors; }
From source file:com.sastix.cms.server.utils.ValidationHelper.java
public String createMessage(List<FieldError> errors) { String message = null;/*from w ww . j a v a 2 s . co m*/ if (errors != null && errors.size() > 0) { List<String> messages = new ArrayList<String>(); for (FieldError error : errors) { messages.add(error.getField() + " " + error.getDefaultMessage()); } Joiner joiner = Joiner.on(", ").skipNulls(); message = joiner.join(messages); } return message; }
From source file:com.thesoftwareguild.addressbook.validation.RestValidationHandler.java
@ExceptionHandler(MethodArgumentNotValidException.class) @ResponseStatus(HttpStatus.BAD_REQUEST)// ww w . j a v a 2 s . com @ResponseBody public ValidationErrorContainer processValidationErrors(MethodArgumentNotValidException e) { BindingResult result = e.getBindingResult(); List<FieldError> fieldErrors = result.getFieldErrors(); ValidationErrorContainer errors = new ValidationErrorContainer(); for (FieldError currentError : fieldErrors) { errors.addValidationError(currentError.getField(), currentError.getDefaultMessage()); } return errors; }
From source file:com.tsg.contactlistmvc.validation.RestValidationHandler.java
@ExceptionHandler(MethodArgumentNotValidException.class) @ResponseStatus(HttpStatus.BAD_REQUEST)/*from ww w.j a va 2 s .c om*/ @ResponseBody public ValidationErrorContainer processValidationErrors(MethodArgumentNotValidException e) { BindingResult result = e.getBindingResult(); List<FieldError> fieldErrors = result.getFieldErrors(); ValidationErrorContainer errors = new ValidationErrorContainer(); for (FieldError currentError : fieldErrors) { errors.addValidationError(currentError.getField(), currentError.getDefaultMessage()); } return errors; }
From source file:com.swcguild.addressbookmvc.validation.RestValidationHandler.java
@ExceptionHandler(MethodArgumentNotValidException.class) @ResponseStatus(HttpStatus.BAD_REQUEST)/* www .jav a 2 s.c om*/ @ResponseBody public ValidationErrorContainer processValidationErrors(MethodArgumentNotValidException e) { BindingResult result = e.getBindingResult(); List<FieldError> fieldErrors = result.getFieldErrors(); ValidationErrorContainer errors = new ValidationErrorContainer(); for (FieldError currentError : fieldErrors) { errors.addValidationError(currentError.getField(), currentError.getDefaultMessage()); } return errors; }