List of usage examples for org.springframework.web.bind MethodArgumentNotValidException getBindingResult
public BindingResult getBindingResult()
From source file:cz.fi.muni.pa036.airticketbooking.rest.handler.RestErrorHandler.java
@ExceptionHandler(MethodArgumentNotValidException.class) @ResponseStatus(HttpStatus.BAD_REQUEST)//from w ww. j a v a2 s . c om @ResponseBody public ValidationErrorDTO processValidationError(MethodArgumentNotValidException ex) { BindingResult result = ex.getBindingResult(); List<FieldError> fieldErrors = result.getFieldErrors(); return processFieldErrors(fieldErrors); }
From source file:com.mycompany.addressbookmvc.validation.RestValidationHandler.java
@ExceptionHandler(MethodArgumentNotValidException.class) @ResponseStatus(HttpStatus.BAD_REQUEST)/*from ww w .j av a 2 s. c o m*/ @ResponseBody public ValidationErrorContainer processValidationErrors(MethodArgumentNotValidException ex) { BindingResult result = ex.getBindingResult(); List<FieldError> fieldErrors = result.getFieldErrors(); ValidationErrorContainer container = new ValidationErrorContainer(); for (FieldError error : fieldErrors) { ValidationError valError = new ValidationError(); valError.setFieldName(error.getField()); valError.setMessage(error.getDefaultMessage()); container.AddError(valError); } return container; }
From source file:com.tsg.cms.validation.RESTValidationHandler.java
@ExceptionHandler(MethodArgumentNotValidException.class) @ResponseStatus(HttpStatus.BAD_REQUEST)//from ww w . jav a 2s . c o m @ResponseBody public ValidationErrorContainer processMethodArgumentNotValidException(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.create.controller.BeanValidatorErrorHandler.java
@ExceptionHandler @ResponseStatus(HttpStatus.BAD_REQUEST)//from w ww. ja v a 2 s . c o m @ResponseBody public ValidationResult<?> processValidationErrors(MethodArgumentNotValidException exception) { final BindingResult result = exception.getBindingResult(); final List<ObjectError> fieldErrors = result.getAllErrors(); final List<?> targets = getTargets(result); return processValidationErrors(targets, fieldErrors); }
From source file:org.easy.spring.web.ValidationSupport.java
@ExceptionHandler(MethodArgumentNotValidException.class) @ResponseStatus(HttpStatus.BAD_REQUEST)// w ww.j ava 2s. co m @ResponseBody public ValidationError processValidationError(MethodArgumentNotValidException ex) { BindingResult errors = ex.getBindingResult(); ValidationError result = new ValidationError(errors.getObjectName(), errors.getNestedPath(), errors.getErrorCount(), errors.getFieldErrors()); return result;//processFieldErrors(fieldErrors); }
From source file:de.knightsoftnet.validators.server.controller.RestErrorHandler.java
/** * handle validation errors./*from w w w .jav a 2 s.c o m*/ * * @param pexception exception which is thrown when data is invalid. * @return ValidationResultData with validation errors */ @ExceptionHandler(MethodArgumentNotValidException.class) @ResponseStatus(HttpStatus.BAD_REQUEST) @ResponseBody public ValidationResultInterface processValidationError(final MethodArgumentNotValidException pexception) { final BindingResult result = pexception.getBindingResult(); final List<FieldError> fieldErrors = result.getFieldErrors(); return this.processFieldErrors(fieldErrors); }
From source file:com.vmware.bdd.rest.advice.RestValidationErrorHandler.java
@ExceptionHandler(MethodArgumentNotValidException.class) @ResponseStatus(HttpStatus.BAD_REQUEST)/* ww w . j ava 2 s . c o m*/ @ResponseBody public BddErrorMessage processValidationError(MethodArgumentNotValidException ex) { BindingResult result = ex.getBindingResult(); List<FieldError> fieldErrors = result.getFieldErrors(); BddException validationException = new ValidationException(processFieldErrors(fieldErrors).getErrors()); return ServerErrorMessages.fromException(validationException); }
From source file:com.epam.ta.reportportal.commons.exception.message.ArgumentNotValidMessageBuilder.java
@Override public String buildMessage(MethodArgumentNotValidException e) { StringBuilder sb = new StringBuilder(); for (ObjectError error : e.getBindingResult().getAllErrors()) { sb.append("[").append(messageSource.getMessage(error, LocaleContextHolder.getLocale())).append("] "); }//w w w . j av a 2 s .co m return sb.toString(); }
From source file:com.seabee.snapdragon.validation.RestValidationHandler.java
@ExceptionHandler(MethodArgumentNotValidException.class) // #3: Specify the HTTP Status code to return when an error occurs @ResponseStatus(HttpStatus.BAD_REQUEST)/*from ww w. j av a2 s. c o m*/ // #4: Let Spring know that we have something to return in the body of the // response. In this case it will be a ValidationErrorContainer containing // a ValidationError object for each field that did not pass validation. @ResponseBody public ValidationErrorContainer processValidationErrors(MethodArgumentNotValidException e) { // #5: get the Binding Result and all field errors BindingResult result = e.getBindingResult(); List<FieldError> fieldErrors = result.getFieldErrors(); // #6: Create a new ValidationError for each fieldError in the Binding Result ValidationErrorContainer errors = new ValidationErrorContainer(); for (FieldError currentError : fieldErrors) { errors.addValidationError(currentError.getField(), currentError.getDefaultMessage()); } return errors; }
From source file:com.mycompany.contactlistmvc.validation.RestValidationHandler.java
@ExceptionHandler(MethodArgumentNotValidException.class) // #3: Specify the Http Status code to return when an error occurs @ResponseStatus(HttpStatus.BAD_REQUEST)// w ww . j a va 2s . co m // #4: Let Spring know that we have something to return in the body of the // response. In this case it will be a ValidationErrorContainer containing // a ValidationError object for each field that did not pass validation. @ResponseBody public ValidationErrorContainer processValidationErrors(MethodArgumentNotValidException e) { // #5: get the Binding Result and all field errors BindingResult result = e.getBindingResult(); List<FieldError> fieldErrors = result.getFieldErrors(); // #6: Create a new ValidationError for each fieldError in the Binding Result ValidationErrorContainer errors = new ValidationErrorContainer(); for (FieldError currentError : fieldErrors) { errors.addValidationError(currentError.getField(), currentError.getDefaultMessage()); } return errors; }