當前位置: 首頁>>代碼示例>>Java>>正文


Java BeanPropertyBindingResult.getFieldErrors方法代碼示例

本文整理匯總了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());
    }
 
開發者ID:bartgerard,項目名稱:ubrew_v0.1,代碼行數:16,代碼來源:ApplicationValidatorTest.java

示例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;
		}
	}
}
 
開發者ID:yangjm,項目名稱:winlet,代碼行數:37,代碼來源:FormImpl.java

示例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;
}
 
開發者ID:eea,項目名稱:eionet.webq,代碼行數:10,代碼來源:AbstractContextControllerTests.java


注:本文中的org.springframework.validation.BeanPropertyBindingResult.getFieldErrors方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。