List of usage examples for org.springframework.validation FieldError getField
public String getField()
From source file:com.google.ie.dto.ViewStatus.java
/** * @param errors/*from w ww. ja v a 2s. c om*/ */ 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 ww w . j a v a 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:org.opentides.util.CrudUtil.java
/** * Converts the binding error messages to list of MessageResponse * /*from ww w . ja v a2 s .com*/ * @param bindingResult */ public static List<MessageResponse> convertErrorMessage(BindingResult bindingResult, Locale locale, MessageSource messageSource) { List<MessageResponse> errorMessages = new ArrayList<MessageResponse>(); if (bindingResult.hasErrors()) { for (ObjectError error : bindingResult.getAllErrors()) { MessageResponse message = null; if (error instanceof FieldError) { FieldError ferror = (FieldError) error; message = new MessageResponse(MessageResponse.Type.error, error.getObjectName(), ferror.getField(), error.getCodes(), error.getArguments()); } else message = new MessageResponse(MessageResponse.Type.error, error.getObjectName(), null, error.getCodes(), error.getArguments()); message.setMessage(messageSource.getMessage(message, locale)); errorMessages.add(message); } } return errorMessages; }
From source file:com.teamd.taxi.validation.DriverValidateUtil.java
@Override public List<FieldError> filterErrors(List<FieldError> errors) { HashMap<String, FieldError> result = new HashMap<>(); for (FieldError error : errors) { String field = error.getField(); if (!result.keySet().contains(field)) { result.put(field, error);/*ww w.java 2 s .c o m*/ } else { result.put(field, higherError(result.get(field), error)); } } return new ArrayList<>(result.values()); }
From source file:com.tsguild.dolphinblog.controller.RestValidationHandler.java
@ExceptionHandler(MethodArgumentNotValidException.class) @ResponseBody/* ww w .ja va 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 ww w . j av a2 s .c o 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)// w ww .j a va 2s.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.tsg.contactlistmvc.validation.RestValidationHandler.java
@ExceptionHandler(MethodArgumentNotValidException.class) @ResponseStatus(HttpStatus.BAD_REQUEST)// w w w .j ava 2 s. c o m @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)//from w w w . jav a2 s . c o m @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.sg.addressbookmvc.validation.RestValidationHandler.java
@ExceptionHandler(MethodArgumentNotValidException.class) @ResponseStatus(HttpStatus.BAD_REQUEST)//w w w . j a v a 2s . 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; }