List of usage examples for org.springframework.validation FieldError getDefaultMessage
@Override
@Nullable
public String getDefaultMessage()
From source file:org.jasig.portlet.blackboardvcportlet.mvc.sessionmngr.ManageMediaFilesController.java
protected Map<String, String> getFieldErrors(BindingResult bindingResult) { final Map<String, String> fieldErrors = new LinkedHashMap<String, String>(); for (FieldError error : bindingResult.getFieldErrors()) { fieldErrors.put(error.getField(), error.getDefaultMessage()); }/*from ww w.j a v a 2 s. c om*/ return fieldErrors; }
From source file:com.oak_yoga_studio.controller.ProductController.java
@RequestMapping(value = "/productEdit", method = RequestMethod.POST) public String updateProduct(@Valid Product product, BindingResult result, @RequestParam("file") MultipartFile file) { if (!result.hasErrors()) { try {/*from w w w .j a v a 2s . c o m*/ product.setImage(file.getBytes()); product.setStatus("ACTIVE"); productService.updateProduct(product); } catch (IOException ex) { ex.printStackTrace(); } return "redirect:/products"; } else { for (FieldError err : result.getFieldErrors()) { System.out.println(err.getField() + ": " + err.getDefaultMessage()); } return "editProduct"; } }
From source file:com.google.ie.common.validation.CommentValidator.java
public void validateIdeaComments(Object object, Errors errors) { IdeaComment ideaComment = (IdeaComment) object; ValidationUtils.rejectIfEmptyOrWhitespace(errors, IDEA_KEY, IdeaExchangeConstants.Messages.REQUIRED_FIELD); ValidationUtils.rejectIfEmptyOrWhitespace(errors, TEXT, IdeaExchangeConstants.Messages.REQUIRED_FIELD); if (StringUtils.length(ideaComment.getText()) > COMMENT_LENGTH) { errors.rejectValue(TEXT, IdeaExchangeErrorCodes.COMMENT_LENGTH_EXCEEDS, IdeaExchangeConstants.Messages.COMMENT_LENGTH_EXCEEDS); }//from w ww.jav a2 s. c o m 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()); } } else { log.debug("Validator found no errors"); } } }
From source file:com.google.ie.common.validation.CommentValidator.java
public void validateProjectComments(Object object, Errors errors) { ProjectComment projectComment = (ProjectComment) object; ValidationUtils.rejectIfEmptyOrWhitespace(errors, PROJECT_KEY, IdeaExchangeConstants.Messages.REQUIRED_FIELD); ValidationUtils.rejectIfEmptyOrWhitespace(errors, TEXT, IdeaExchangeConstants.Messages.REQUIRED_FIELD); if (StringUtils.length(projectComment.getText()) > COMMENT_LENGTH) { errors.rejectValue(TEXT, IdeaExchangeErrorCodes.COMMENT_LENGTH_EXCEEDS, IdeaExchangeConstants.Messages.COMMENT_LENGTH_EXCEEDS); }/*from w ww.j a v a 2 s . c o m*/ 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()); } } else { log.debug("Validator found no errors"); } } }
From source file:de.extra.client.core.util.impl.ExtraValidator.java
private String convertToString(final Errors errors) { final List<FieldError> fieldErrors = errors.getFieldErrors(); final StringBuilder stringBuilder = new StringBuilder(fieldErrors.size() + " Konfigurationsfehler: "); final String sep = ";"; for (final FieldError fieldError : fieldErrors) { stringBuilder.append(fieldError.getObjectName()); stringBuilder.append(".").append(fieldError.getField()); stringBuilder.append(" ").append(fieldError.getDefaultMessage()); stringBuilder.append(sep);// ww w . j a v a2s.c o m } return stringBuilder.toString(); }
From source file:com.simplecrud.controller.RegistrationController.java
/** * Process Registration Data// www. j a v a2 s .c o m * * @param member * @param result * @param model * @param request * @return view */ @RequestMapping(value = "/register", method = RequestMethod.POST) public ModelAndView validateUser(@Valid @ModelAttribute("newMemberForm") ValidateMember member, BindingResult result, Model model, HttpServletRequest request) { FormStatus sFormStatus = new FormStatus(); //if validated form has errors if (result.hasErrors()) { //handle errors in the inputs List<FieldError> errors = result.getFieldErrors(); for (FieldError error : errors) { System.out.println(error.getField() + " - " + error.getDefaultMessage()); if ("username".equals(error.getField())) { //set error message in username input sFormStatus.setsUsername(error.getDefaultMessage()); } if ("password".equals(error.getField())) { //set error message in password input sFormStatus.setsPassword(error.getDefaultMessage()); } if ("email".equals(error.getField())) { //set error message in email input sFormStatus.setsEmail(error.getDefaultMessage()); } } System.out.println(result.getFieldErrors()); return new ModelAndView("redirect:/registration.html?" + "&ErrorUsername=" + sFormStatus.getsUsername() + "" + "&ErrorPassword=" + sFormStatus.getsPassword() + "" + "&ErrorEmail=" + sFormStatus.getsEmail() + "" + "&response=error"); } else { String username = request.getParameter("username"); String password = request.getParameter("password"); String email = request.getParameter("email"); //try to save the form try { newMemberDao.persist(new NewMember(username, password, email)); System.out.println(result + "Form Results - Valid and Saved"); return new ModelAndView("redirect:/registration.html?response=success"); } catch (Exception e) { System.out.println(e.getMessage() + " User Already Exist"); } return new ModelAndView("redirect:/registration.html?response=UserAlreadyExist"); } }
From source file:net.jkratz.igdb.controller.advice.ErrorController.java
private Map<String, Object> convertConstraintViolation(MethodArgumentNotValidException ex) { Map<String, Object> result = Maps.newHashMap(); for (FieldError error : ex.getBindingResult().getFieldErrors()) { result.put(error.getField(), error.getDefaultMessage()); }//from ww w. j av a 2 s . c o m return result; }
From source file:de.knightsoftnet.validators.server.controller.RestErrorHandler.java
private ValidationResultInterface processFieldErrors(final List<FieldError> pfieldErrors) { final ValidationResultInterface validationResult = new ValidationResultData(); for (final FieldError fieldError : pfieldErrors) { final ValidationValueInterface validationDto = new ValidationDto(); validationDto.setPropertyPath(fieldError.getField()); validationDto.setMessage(fieldError.getDefaultMessage()); validationResult.getValidationErrorSet().add(validationDto); }//from ww w. j a va 2s. c o m return validationResult; }
From source file:cz.muni.fi.editor.webapp.controllers.ajax.AjaxUserController.java
@RequestMapping(value = "/", method = RequestMethod.POST) public @ResponseBody ValidationResponse processUpdateuser(Model model, @RequestBody @Valid UserFormProfile userFormProfile, BindingResult bindingResult) { ValidationResponse response = new ValidationResponse(); if (bindingResult.hasErrors()) { response.setStatus("FAIL"); List<ErrorMessage> messages = new ArrayList<>(); for (FieldError error : bindingResult.getFieldErrors()) { ErrorMessage em = new ErrorMessage(); em.setField(error.getField()); em.setMessage(error.getDefaultMessage()); messages.add(em);/* w w w . ja v a 2 s . c om*/ } response.setMessages(messages); } else { try { userService.update(mapper.map(userFormProfile, UserDTO.class)); response.setStatus("SUCCESS"); } catch (FieldException ex) { log.warn(ex); response.setStatus("FAIL"); } } return response; }
From source file:org.terasoluna.tourreservation.app.managecustomer.CustomerBirthdayValidatorTest.java
/** * Date parse Error//from w w w.ja v a 2 s. com */ @Test public void testValidate02() { CustomerBirthdayValidator validator = new CustomerBirthdayValidator(); CustomerForm customer = new CustomerForm(); customer.setCustomerBirthYear(2011); customer.setCustomerBirthMonth(02); customer.setCustomerBirthDay(29); BindingResult result = new DirectFieldBindingResult(customer, "CustomerForm"); // run validator.validate(customer, result); // assert assertThat(result.hasErrors(), is(true)); FieldError error = result.getFieldError("customerBirthYear"); if (error != null) { assertThat(error.getCode(), is("IncorrectDate.customerBirth")); assertThat(error.getDefaultMessage(), is("Incorrect date was entered.")); } else { fail("error"); } }