List of usage examples for org.springframework.validation BindingResult getFieldErrors
List<FieldError> getFieldErrors();
From source file:com.thesoftwareguild.flightmaster.validation.RestValidaitonHandler.java
@ExceptionHandler(MethodArgumentNotValidException.class) @ResponseStatus(HttpStatus.BAD_REQUEST)//from w w w. j av a 2s . 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.seabee.snapdragon.validation.RestValidationHandler.java
@ExceptionHandler(MethodArgumentNotValidException.class) // #3: Specify the HTTP Status code to return when an error occurs @ResponseStatus(HttpStatus.BAD_REQUEST)//ww w . j a v 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.janrain.backplane.server.InvalidRequestException.java
public InvalidRequestException(BindingResult result) { for (FieldError error : result.getFieldErrors()) { fieldErrors.put(error.getField(), error.getDefaultMessage()); }/*from w w w . j a v a 2 s.c o m*/ }
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 www. ja v a2s . 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; }
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)// w w w . j a va 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; }
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 w w . j ava 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.mycompany.capstone.validation.RestValidationHandler.java
@ExceptionHandler(MethodArgumentNotValidException.class) @ResponseStatus(HttpStatus.BAD_REQUEST)/* www .j a v a 2s . c om*/ @ResponseBody public ValidationErrorContainer processValidationErrors(MethodArgumentNotValidException ex) { BindingResult bindResult = ex.getBindingResult(); List<FieldError> fieldErrors = bindResult.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:cz.fi.muni.pa036.airticketbooking.rest.handler.RestErrorHandler.java
@ExceptionHandler(MethodArgumentNotValidException.class) @ResponseStatus(HttpStatus.BAD_REQUEST)/*from w w w.j a v a2 s .c o m*/ @ResponseBody public ValidationErrorDTO processValidationError(MethodArgumentNotValidException ex) { BindingResult result = ex.getBindingResult(); List<FieldError> fieldErrors = result.getFieldErrors(); return processFieldErrors(fieldErrors); }
From source file:com.swcguild.capstoneproject.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. ja va2 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; }
From source file:com.mycompany.addressbookmvc.validation.RestValidationHandler.java
@ExceptionHandler(MethodArgumentNotValidException.class) @ResponseStatus(HttpStatus.BAD_REQUEST)//from w w w .j av a2s .co 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; }