List of usage examples for org.springframework.validation FieldError getDefaultMessage
@Override
@Nullable
public String getDefaultMessage()
From source file:com.sg.addressbookmvc.validation.RestValidationHandler.java
@ExceptionHandler(MethodArgumentNotValidException.class) @ResponseStatus(HttpStatus.BAD_REQUEST)// ww w.j a v a2 s .co 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.jjcosare.calculator.controller.CalculatorController.java
@RequestMapping(value = "/", method = RequestMethod.GET) public @ResponseBody Object getCalculation(@Valid CalculatorForm calculatorForm, BindingResult bindingResult) { Object result = null;/* w ww.java 2 s. c o m*/ if (bindingResult.hasErrors()) { Map<String, String> errorMap = new HashMap<>(); for (FieldError error : bindingResult.getFieldErrors()) { errorMap.put(error.getField(), error.getDefaultMessage()); } result = errorMap; } else { result = calculatorService.getCalculation(calculatorForm); } return result; }
From source file:com.swcguild.blacksmithblogcapstone.validation.RestValidationHandler.java
@ExceptionHandler(MethodArgumentNotValidException.class) @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) @ResponseBody/*from w ww .j a v a 2s . c o m*/ 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.thesoftwareguild.flightmaster.validation.RestValidaitonHandler.java
@ExceptionHandler(MethodArgumentNotValidException.class) @ResponseStatus(HttpStatus.BAD_REQUEST)// www .j av a 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.intel.databackend.handlers.ErrorHandler.java
@ExceptionHandler(BindException.class) public ResponseEntity handleError(BindException ex) { Map<String, String> errors = new HashMap<>(); for (FieldError error : ex.getFieldErrors()) { errors.put(error.getField(), error.getDefaultMessage()); }/* ww w.ja va2s .c om*/ logger.error("Validation error: ", errors); return new ResponseEntity<Map<String, String>>(errors, HttpStatus.BAD_REQUEST); }
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)/* w w w . ja va 2 s .c om*/ // #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.jwt.exceptions.GlobalExceptionHandler.java
@ExceptionHandler(BindException.class) @ResponseStatus(HttpStatus.BAD_REQUEST)/*from w w w . java 2 s. com*/ @ResponseBody public Map handleException(BindException exception) { _LOGGER.log(Level.INFO, (Supplier<String>) exception); List<String> errors = new ArrayList<>(); for (FieldError fe : exception.getFieldErrors()) { errors.add(fe.getDefaultMessage()); } return error(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)/*from ww w . j av a 2 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.tsg.addressbookmvc.validation.RESTValidationHandler.java
@ExceptionHandler(MethodArgumentNotValidException.class) // #3: Specify the HTTP Status code to return when an error occurs @ResponseStatus(HttpStatus.BAD_REQUEST)//from w w w. j a va 2 s . c om // #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.swcguild.vendingmachinemvc.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 v a 2 s.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; }