List of usage examples for org.springframework.validation FieldError getField
public String getField()
From source file:com.github.lynxdb.server.api.http.handlers.EpVhost.java
@RequestMapping(value = "", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity createVhost(Authentication _authentication, @RequestBody @Valid VhostCreationRequest _vcr, BindingResult _bindingResult) {//from ww w .j a v a 2s .c o m if (_bindingResult.hasErrors()) { ArrayList<String> errors = new ArrayList(); _bindingResult.getFieldErrors().forEach((FieldError t) -> { errors.add(t.getField() + ": " + t.getDefaultMessage()); }); return new ErrorResponse(mapper, HttpStatus.BAD_REQUEST, errors.toString()).response(); } Vhost v = new Vhost(_vcr); vhosts.save(v); return ResponseEntity.ok(v); }
From source file:com.github.lynxdb.server.api.http.handlers.EpSuggest.java
@RequestMapping(path = "", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity post(@RequestBody @Valid SuggestRequest _request, Authentication _authentication, BindingResult _bindingResult) {/*from w w w. j a v a2s . c om*/ if (_bindingResult.hasErrors()) { ArrayList<String> errors = new ArrayList(); _bindingResult.getFieldErrors().forEach((FieldError t) -> { errors.add(t.getField() + ": " + t.getDefaultMessage()); }); return new ErrorResponse(mapper, HttpStatus.BAD_REQUEST, errors.toString(), null).response(); } return response(_request, _authentication); }
From source file:com.mycompany.capstone.validation.RestValidationHandler.java
@ExceptionHandler(MethodArgumentNotValidException.class) @ResponseStatus(HttpStatus.BAD_REQUEST)/*from ww w . java 2 s .co m*/ @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:com.zq.fin.seckill.web.BaseController.java
protected void validate(BindingResult result, Model model){ ObjectError gloerror = result.getGlobalError(); List<FieldError> errors= result.getFieldErrors(); // w w w .j a va 2 s . c o m if(ObjectUtil.isNotEmpty(gloerror)){ model.addAttribute("glo", gloerror.getDefaultMessage()); } for(FieldError fieldError:errors){ model.addAttribute(fieldError.getField(), fieldError.getDefaultMessage()); } }
From source file:com.github.lynxdb.server.api.http.handlers.EpUser.java
@RequestMapping(value = "", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity createUser(Authentication _authentication, @RequestBody @Valid UserCreationRequest _ucr, BindingResult _bindingResult) {/* w w w . j a va2s. c om*/ if (_bindingResult.hasErrors()) { ArrayList<String> errors = new ArrayList(); _bindingResult.getFieldErrors().forEach((FieldError t) -> { errors.add(t.getField() + ": " + t.getDefaultMessage()); }); return new ErrorResponse(mapper, HttpStatus.BAD_REQUEST, errors.toString()).response(); } User u = new User(_ucr); if (users.create(u)) { return ResponseEntity.ok(u); } else { return new ErrorResponse(mapper, HttpStatus.BAD_REQUEST, "User already exists").response(); } }
From source file:com.google.ie.common.validation.AuditValidator.java
@Override public void validate(Object target, Errors errors) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, IdeaExchangeConstants.USER_KEY, IdeaExchangeErrorCodes.FIELD_REQUIRED, IdeaExchangeConstants.Messages.REQUIRED_FIELD); ValidationUtils.rejectIfEmptyOrWhitespace(errors, IdeaExchangeConstants.ENTITY_KEY, IdeaExchangeErrorCodes.FIELD_REQUIRED, IdeaExchangeConstants.Messages.REQUIRED_FIELD); ValidationUtils.rejectIfEmptyOrWhitespace(errors, IdeaExchangeConstants.ACTION, IdeaExchangeErrorCodes.FIELD_REQUIRED, IdeaExchangeConstants.Messages.REQUIRED_FIELD); ValidationUtils.rejectIfEmptyOrWhitespace(errors, IdeaExchangeConstants.ENTITY_TYPE, IdeaExchangeErrorCodes.FIELD_REQUIRED, IdeaExchangeConstants.Messages.REQUIRED_FIELD); ValidationUtils.rejectIfEmptyOrWhitespace(errors, IdeaExchangeConstants.AUDIT_DATE, IdeaExchangeErrorCodes.FIELD_REQUIRED, IdeaExchangeConstants.Messages.REQUIRED_FIELD); if (log.isDebugEnabled()) { if (errors.hasErrors()) { log.debug("Validator found " + errors.getErrorCount() + " errors"); for (Iterator<FieldError> iterator = errors.getFieldErrors().iterator(); iterator.hasNext();) { FieldError fieldError = iterator.next(); log.debug("Error found in field: " + fieldError.getField() + " Message :" + fieldError.getDefaultMessage()); }/*from w w w. ja v a 2 s .c om*/ } else { log.debug("Validator found no errors"); } } }
From source file:org.ualerts.fixed.web.controller.AbstractFormController.java
private Map<String, List<String>> getFieldErrors(Errors errors) { if (!errors.hasFieldErrors()) return null; Map<String, List<String>> fieldErrors = new HashMap<String, List<String>>(); for (FieldError error : errors.getFieldErrors()) { if (!fieldErrors.containsKey(error.getField())) fieldErrors.put(error.getField(), new ArrayList<String>()); fieldErrors.get(error.getField()).add(getMessage(error.getCode())); }// w w w . j ava2s .c o m return fieldErrors; }
From source file:com.nicodewet.web.SubscribeController.java
@RequestMapping(value = "/subscribeth.json", method = RequestMethod.POST) public @ResponseBody ValidationResponse processForm(@Valid final Subscription subscription, final BindingResult bindingResult, final ModelMap model) { logger.info("Validation"); ValidationResponse res = new ValidationResponse(); if (!bindingResult.hasErrors()) { res.setStatus("SUCCESS"); } else {//w w w. ja v a 2 s .co m res.setStatus("FAIL"); List<FieldError> allErrors = bindingResult.getFieldErrors(); List<ErrorMessage> errorMesages = new ArrayList<ErrorMessage>(); for (FieldError objectError : allErrors) { errorMesages.add(new ErrorMessage(objectError.getField(), objectError.getField() + " " + objectError.getDefaultMessage())); } res.setErrorMessageList(errorMesages); } return res; }
From source file:com.mycompany.addressbookmvc.validation.RestValidationHandler.java
@ExceptionHandler(MethodArgumentNotValidException.class) @ResponseStatus(HttpStatus.BAD_REQUEST)//w w w . j a va2s . com @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.github.lynxdb.server.api.http.handlers.EpUser.java
@RequestMapping(value = "/{userLogin}", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity updateUser(Authentication _authentication, @PathVariable("userLogin") String userLogin, @RequestBody @Valid UserUpdateRequest _ucr, BindingResult _bindingResult) { if (_bindingResult.hasErrors()) { ArrayList<String> errors = new ArrayList(); _bindingResult.getFieldErrors().forEach((FieldError t) -> { errors.add(t.getField() + ": " + t.getDefaultMessage()); });/*ww w . ja v a2 s. c o m*/ return new ErrorResponse(mapper, HttpStatus.BAD_REQUEST, errors.toString()).response(); } User user = users.byLogin(userLogin); if (user == null) { return new ErrorResponse(mapper, HttpStatus.BAD_REQUEST, "User does not exist.", null).response(); } if (_ucr.password != null && !_ucr.password.isEmpty()) { user.setPassword(_ucr.password); } if (_ucr.rank != null) { user.setRank(_ucr.rank); } users.save(user); return ResponseEntity.ok(user); }