本文整理匯總了Java中org.springframework.validation.BeanPropertyBindingResult.getFieldErrors方法的典型用法代碼示例。如果您正苦於以下問題:Java BeanPropertyBindingResult.getFieldErrors方法的具體用法?Java BeanPropertyBindingResult.getFieldErrors怎麽用?Java BeanPropertyBindingResult.getFieldErrors使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.springframework.validation.BeanPropertyBindingResult
的用法示例。
在下文中一共展示了BeanPropertyBindingResult.getFieldErrors方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: test2
import org.springframework.validation.BeanPropertyBindingResult; //導入方法依賴的package包/類
@Test
public void test2() {
BeanPropertyBindingResult errors = new BeanPropertyBindingResult(new User(), "user");
errors.addError(new ObjectError("foo","message1"));
errors.addError(new ObjectError("foo", "message2"));
ValidationUtils.rejectIfEmpty(errors, "username", "error.username.null");
for (FieldError fieldError : errors.getFieldErrors()) {
System.out.println(fieldError.getRejectedValue() + " " + fieldError.getField());
}
// ValidationException originalException=new ValidationException(errors);
// Error error=new Error(originalException);
// Throwable exception=error.getException();
// assertSame(originalException.getClass(),exception.getClass());
// assertEquals(originalException.getMessage(),exception.getMessage());
}
示例2: mergeBindingResult
import org.springframework.validation.BeanPropertyBindingResult; //導入方法依賴的package包/類
protected void mergeBindingResult(String field,
Collection<BindingResult> values) {
if (disabledFields.contains(field))
return;
HttpServletRequest request = ContextUtils.getRequest();
WebApplicationContext context = RequestContextUtils
.findWebApplicationContext(request);
Locale locale = RequestContextUtils.getLocale(request);
for (BindingResult val : values) {
if (!(val instanceof BeanPropertyBindingResult))
continue;
BeanPropertyBindingResult br = (BeanPropertyBindingResult) val;
if (br.getTarget() != null && br.getFieldType(field) != null
|| br.getObjectName().equals(field)) {
// merge Spring conversion & validation errors
List<FieldError> errors = br.getFieldErrors(field);
if (errors != null && errors.size() > 0) {
errors.forEach(p -> {
addError(field, context.getMessage(p, locale));
});
} else if (getErrors(field) == null && br.getTarget() != null) {
// no error, apply Spring formatter
String value = WinletDefaultFormattingConversionService
.format(br.getPropertyAccessor(), br.getTarget(),
field);
if (value != null)
setValue(field, value.toString());
}
break;
}
}
}
示例3: getFieldErrorsFromMvcResultAndAssertThatFieldErrorCountIs
import org.springframework.validation.BeanPropertyBindingResult; //導入方法依賴的package包/類
protected List<FieldError> getFieldErrorsFromMvcResultAndAssertThatFieldErrorCountIs(MvcResult result, int size) {
BeanPropertyBindingResult bindingResult =
(BeanPropertyBindingResult) result.getModelAndView().getModelMap()
.get(bindingResultPropertyNameInModel());
List<FieldError> fieldErrors = bindingResult.getFieldErrors();
assertThat("Field errors=" + fieldErrors, bindingResult.getFieldErrorCount(), equalTo(size));
return fieldErrors;
}