List of usage examples for org.springframework.validation FieldError getRejectedValue
@Nullable
public Object getRejectedValue()
From source file:org.zht.framework.validate.ValidateHandler.java
public static String getDefaultError(BindingResult result) { if (result.hasErrors()) { List<FieldError> fieldEist = result.getFieldErrors(); if (fieldEist != null && fieldEist.size() > 0) { FieldError fieldError = fieldEist.get(0); fieldError.getCode();//from ww w . j av a 2 s. c o m String prefix = "\r\n" + "???"; String value = "{" + (fieldError.getRejectedValue() == null ? " " : fieldError.getRejectedValue()) + "}"; String message = "" + fieldError.getDefaultMessage(); return prefix + "" + value + "\r\n" + message; } else { List<ObjectError> allErrorlist = result.getAllErrors(); ObjectError oe = allErrorlist.get(0); return "" + oe.getDefaultMessage(); } } else { return null; } }
From source file:com.cisco.cta.taxii.adapter.settings.BindExceptionHandler.java
@Override public void handle(BindException e) { for (ObjectError error : e.getAllErrors()) { StringBuilder b = new StringBuilder().append("Error in application.yml").append(", section ") .append(error.getObjectName()); if (error instanceof FieldError) { FieldError fieldError = (FieldError) error; b.append(", ").append(fieldError.getField()).append(" has illegal value ") .append(fieldError.getRejectedValue()); }/*ww w . j a va 2 s . c om*/ err.println(b.toString()); } }
From source file:org.tonguetied.web.ChangePasswordFormValidatorTest.java
/** * Test method for {@link org.tonguetied.web.ChangePasswordFormValidator#validate(java.lang.Object, org.springframework.validation.Errors)}. *///from w ww. j a v a2s .c o m @Test public final void testValidateInvalidObject() { ChangePasswordFormValidator validator = new ChangePasswordFormValidator(); Errors errors = new BindException(this.form, "changePasswordForm"); validator.validate(this.form, errors); assertFalse(errors.getAllErrors().isEmpty()); FieldError error = errors.getFieldError(fieldName); if (FIELD_NEW_PASSWORD.equals(fieldName)) { assertEquals(this.form.getNewPassword(), error.getRejectedValue()); } if (FIELD_NEW_REPEATED_PASSWORD.equals(fieldName)) { assertEquals(this.form.getNewRepeatedPassword(), error.getRejectedValue()); } assertFalse(error.isBindingFailure()); }
From source file:org.tonguetied.web.CountryValidatorTest.java
/** * Test method for {@link org.tonguetied.web.CountryValidator#validate(java.lang.Object, org.springframework.validation.Errors)}. */// w w w .j ava 2 s .c o m @Test public final void testValidateInvalidObject() { CountryValidator validator = new CountryValidator(); validator.setKeywordService(keywordService); Errors errors = new BindException(this.country, "country"); validator.validate(this.country, errors); assertFalse(errors.getAllErrors().isEmpty()); FieldError error = errors.getFieldError(fieldName); if (FIELD_NAME.equals(fieldName)) { assertEquals(this.country.getName(), error.getRejectedValue()); } else if (FIELD_CODE.equals(fieldName)) { assertEquals(this.country.getCode(), error.getRejectedValue()); } assertFalse(error.isBindingFailure()); }
From source file:org.tonguetied.web.AccountFormValidatorTest.java
/** * Test method for//from www . j av a 2 s . co m * {@link org.tonguetied.web.AccountFormValidator#validate(java.lang.Object, org.springframework.validation.Errors)}. */ @Test public final void testValidateInvalidObject() { AccountFormValidator validator = new AccountFormValidator(); Errors errors = new BindException(this.user, "user"); validator.validate(this.user, errors); assertFalse(errors.getAllErrors().isEmpty()); FieldError error = errors.getFieldError(fieldName); if (FIELD_FIRSTNAME.equals(fieldName)) { assertEquals(this.user.getFirstName(), error.getRejectedValue()); } if (FIELD_LASTNAME.equals(fieldName)) { assertEquals(this.user.getLastName(), error.getRejectedValue()); } if (FIELD_EMAIL.equals(fieldName)) { assertEquals(this.user.getEmail(), error.getRejectedValue()); } assertFalse(error.isBindingFailure()); }
From source file:org.tonguetied.web.LanguageValidatorTest.java
/** * Test method for {@link org.tonguetied.web.LanguageValidator#validate(java.lang.Object, org.springframework.validation.Errors)}. *///from ww w . jav a 2 s . c om @Test public final void testValidateInvalidObject() { LanguageValidator validator = new LanguageValidator(); validator.setKeywordService(keywordService); Errors errors = new BindException(this.language, "language"); validator.validate(this.language, errors); assertFalse(errors.getAllErrors().isEmpty()); FieldError error = errors.getFieldError(fieldName); if (FIELD_NAME.equals(fieldName)) { assertEquals(this.language.getName(), error.getRejectedValue()); } else if (FIELD_CODE.equals(fieldName)) { assertEquals(this.language.getCode(), error.getRejectedValue()); } assertFalse(error.isBindingFailure()); }
From source file:org.tonguetied.web.BundleValidatorTest.java
/** * Test method for {@link org.tonguetied.web.BundleValidator#validate(java.lang.Object, org.springframework.validation.Errors)}. *//*from w w w . j a va 2 s .c o m*/ @Test public final void testValidateInvalidObject() { BundleValidator validator = new BundleValidator(); validator.setKeywordService(keywordService); Errors errors = new BindException(this.bundle, "bundle"); validator.validate(this.bundle, errors); assertFalse(errors.getAllErrors().isEmpty()); FieldError error = errors.getFieldError(fieldName); if (FIELD_NAME.equals(fieldName)) { assertEquals(this.bundle.getName(), error.getRejectedValue()); } else if (FIELD_RESOURCE_NAME.equals(fieldName)) { assertEquals(this.bundle.getResourceName(), error.getRejectedValue()); } assertFalse(error.isBindingFailure()); }
From source file:org.tonguetied.web.KeywordTranslationValidatorTest.java
/** * Test method for {@link org.tonguetied.web.KeywordValidator#validate(java.lang.Object, org.springframework.validation.Errors)}. *//* w w w .j a v a2 s . c o m*/ @Test public final void testValidate() { KeywordValidator validator = new KeywordValidator(); final Keyword keyword = new Keyword(); keyword.setTranslations(translations); Errors errors = new BindException(keyword, "keyword"); validator.validateDuplicates(translations, predicate, errors); assertFalse(errors.getAllErrors().isEmpty()); FieldError error = errors.getFieldError(fieldName); if (FIELD_TRANSLATIONS.equals(fieldName)) { assertEquals(translations, error.getRejectedValue()); assertEquals(1, errors.getErrorCount()); } else { fail("cannot match error field"); } assertFalse(error.isBindingFailure()); }
From source file:org.tonguetied.web.ImportValidatorTest.java
/** * Test method for/*from w w w . j a v a2s. c o m*/ * {@link org.tonguetied.web.ImportValidator#validate(Object, Errors)}. */ @Test public final void testValidateInvalidObject() { ImportValidator validator = new ImportValidator(); Errors errors = new BindException(this.importBean, "importBean"); validator.validate(this.importBean, errors); assertFalse(errors.getAllErrors().isEmpty()); FieldError error = errors.getFieldError(fieldName); if (FIELD_FORMAT_TYPE.equals(fieldName)) { assertEquals(this.importBean.getParameters().getFormatType(), error.getRejectedValue()); } if (FIELD_TRANSLATION_STATE.equals(fieldName)) { assertEquals(this.importBean.getParameters().getTranslationState(), error.getRejectedValue()); } if (FIELD_FILE_NAME.equals(fieldName)) { assertEquals(this.importBean.getFileUploadBean().getFile().getName(), error.getRejectedValue()); } assertFalse(error.isBindingFailure()); }
From source file:com.rockagen.gnext.controller.ApplicationController.java
/** * Handle errors//from w w w . ja v a 2 s . c om * * @param errors * @return */ public ErrorMsg error(Errors errors) { FieldError e = errors.getFieldError(); ErrorMsg em = new ErrorMsg(); em.field = e.getField(); em.message = e.getDefaultMessage(); em.value = e.getRejectedValue(); return em; }