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


Java BeanPropertyBindingResult類代碼示例

本文整理匯總了Java中org.springframework.validation.BeanPropertyBindingResult的典型用法代碼示例。如果您正苦於以下問題:Java BeanPropertyBindingResult類的具體用法?Java BeanPropertyBindingResult怎麽用?Java BeanPropertyBindingResult使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


BeanPropertyBindingResult類屬於org.springframework.validation包,在下文中一共展示了BeanPropertyBindingResult類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testValidateErrors

import org.springframework.validation.BeanPropertyBindingResult; //導入依賴的package包/類
@Test
public void testValidateErrors(){
	
	User user = new User(){
		{
			setUserName("ey");
			setFirstName("Eyup");
			setLastName("Gevenim");
			setEmail("[email protected]");
			setPassword("123");
			setConfirmPassword("12");
		}
	};
	
	Errors errors = new BeanPropertyBindingResult(user, "user");
	userValidation.validate(user, errors);
	assertTrue(errors.hasErrors());
	assertTrue( errors.getErrorCount() == 3 );
	assertEquals("Kullan\u0131c\u0131 ad\u0131 en az �� karekter olmal\u0131.", 
			getConfiguredMessage(errors.getFieldError("UserName")));
	
}
 
開發者ID:eyupgevenim,項目名稱:SpringMvcBlog,代碼行數:23,代碼來源:UserValidationTests.java

示例2: testValidateSuccess

import org.springframework.validation.BeanPropertyBindingResult; //導入依賴的package包/類
@Test
public void testValidateSuccess() throws Exception {
	
	User user = new User(){
		{
			setUserName("testSuccess");
			setFirstName("Test");
			setLastName("Test");
			setEmail("[email protected]");
			setPassword("123");
			setConfirmPassword("123");
		}
	};
	
	Errors errors = new BeanPropertyBindingResult(user, "user");
	userValidation.validate(user, errors);
	assertFalse(errors.hasErrors()); 
}
 
開發者ID:eyupgevenim,項目名稱:SpringMvcBlog,代碼行數:19,代碼來源:UserValidationTests.java

示例3: SiteOptionMapDtoValidationTests

import org.springframework.validation.BeanPropertyBindingResult; //導入依賴的package包/類
@Test
public void SiteOptionMapDtoValidationTests() {

    SiteOptionMapDTO siteOptionMapDTO = SiteOptionMapDTO.withGeneralSettings(
            null,
            siteOptions.getSiteDescription(),
            siteOptions.getAddGoogleAnalytics(),
            siteOptions.getGoogleAnalyticsTrackingId(),
            siteOptions.getUserRegistration())
            .build();

    Errors errors = new BeanPropertyBindingResult(siteOptionMapDTO, "siteOptionMapDTO");
    ValidationUtils.invokeValidator(new SiteOptionMapDtoValidator(), siteOptionMapDTO, errors);
    assertTrue(errors.hasFieldErrors("siteName"));
    assertEquals("EMPTY", errors.getFieldError("siteName").getCode());

}
 
開發者ID:mintster,項目名稱:nixmash-blog,代碼行數:18,代碼來源:SiteOptionTests.java

示例4: testValidationError

import org.springframework.validation.BeanPropertyBindingResult; //導入依賴的package包/類
@Test
public void testValidationError(){
	Blog blog = new Blog(){
		{
			setBlogName("te");
			setBlogUrl("Test Blog");
		}
	};
	
	Errors errors = new BeanPropertyBindingResult(blog, "blog");
	blogValidation.validate(blog, errors);
	assertTrue(errors.hasErrors());
	assertTrue( errors.getErrorCount() == 1 );
	assertEquals("Blog ad\u0131 en az �� karekter olmal\u0131.", 
			getConfiguredMessage(errors.getFieldError("BlogName")));
	
}
 
開發者ID:eyupgevenim,項目名稱:SpringMvcBlog,代碼行數:18,代碼來源:BlogValidationTests.java

示例5: validate

import org.springframework.validation.BeanPropertyBindingResult; //導入依賴的package包/類
/**
 * Validate the payload if applicable.
 * <p>The default implementation checks for {@code @javax.validation.Valid},
 * Spring's {@link org.springframework.validation.annotation.Validated},
 * and custom annotations whose name starts with "Valid".
 * @param message the currently processed message
 * @param parameter the method parameter
 * @param target the target payload object
 * @throws MethodArgumentNotValidException in case of binding errors
 */
protected void validate(Message<?> message, MethodParameter parameter, Object target) {
	if (this.validator == null) {
		return;
	}
	for (Annotation ann : parameter.getParameterAnnotations()) {
		Validated validatedAnn = AnnotationUtils.getAnnotation(ann, Validated.class);
		if (validatedAnn != null || ann.annotationType().getSimpleName().startsWith("Valid")) {
			Object hints = (validatedAnn != null ? validatedAnn.value() : AnnotationUtils.getValue(ann));
			Object[] validationHints = (hints instanceof Object[] ? (Object[]) hints : new Object[] {hints});
			BeanPropertyBindingResult bindingResult =
					new BeanPropertyBindingResult(target, getParameterName(parameter));
			if (!ObjectUtils.isEmpty(validationHints) && this.validator instanceof SmartValidator) {
				((SmartValidator) this.validator).validate(target, bindingResult, validationHints);
			}
			else {
				this.validator.validate(target, bindingResult);
			}
			if (bindingResult.hasErrors()) {
				throw new MethodArgumentNotValidException(message, parameter, bindingResult);
			}
			break;
		}
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:35,代碼來源:PayloadArgumentResolver.java

示例6: testSpringValidation

import org.springframework.validation.BeanPropertyBindingResult; //導入依賴的package包/類
@Test
public void testSpringValidation() throws Exception {
	LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
	validator.afterPropertiesSet();
	ValidPerson person = new ValidPerson();
	BeanPropertyBindingResult result = new BeanPropertyBindingResult(person, "person");
	validator.validate(person, result);
	assertEquals(2, result.getErrorCount());
	FieldError fieldError = result.getFieldError("name");
	assertEquals("name", fieldError.getField());
	List<String> errorCodes = Arrays.asList(fieldError.getCodes());
	assertEquals(4, errorCodes.size());
	assertTrue(errorCodes.contains("NotNull.person.name"));
	assertTrue(errorCodes.contains("NotNull.name"));
	assertTrue(errorCodes.contains("NotNull.java.lang.String"));
	assertTrue(errorCodes.contains("NotNull"));
	fieldError = result.getFieldError("address.street");
	assertEquals("address.street", fieldError.getField());
	errorCodes = Arrays.asList(fieldError.getCodes());
	assertEquals(5, errorCodes.size());
	assertTrue(errorCodes.contains("NotNull.person.address.street"));
	assertTrue(errorCodes.contains("NotNull.address.street"));
	assertTrue(errorCodes.contains("NotNull.street"));
	assertTrue(errorCodes.contains("NotNull.java.lang.String"));
	assertTrue(errorCodes.contains("NotNull"));
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:27,代碼來源:ValidatorFactoryTests.java

示例7: testSpringValidationWithClassLevel

import org.springframework.validation.BeanPropertyBindingResult; //導入依賴的package包/類
@Test
public void testSpringValidationWithClassLevel() throws Exception {
	LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
	validator.afterPropertiesSet();
	ValidPerson person = new ValidPerson();
	person.setName("Juergen");
	person.getAddress().setStreet("Juergen's Street");
	BeanPropertyBindingResult result = new BeanPropertyBindingResult(person, "person");
	validator.validate(person, result);
	assertEquals(1, result.getErrorCount());
	ObjectError globalError = result.getGlobalError();
	List<String> errorCodes = Arrays.asList(globalError.getCodes());
	assertEquals(2, errorCodes.size());
	assertTrue(errorCodes.contains("NameAddressValid.person"));
	assertTrue(errorCodes.contains("NameAddressValid"));
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:17,代碼來源:ValidatorFactoryTests.java

示例8: testSpringValidationWithErrorInListElement

import org.springframework.validation.BeanPropertyBindingResult; //導入依賴的package包/類
@Test
public void testSpringValidationWithErrorInListElement() throws Exception {
	LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
	validator.afterPropertiesSet();
	ValidPerson person = new ValidPerson();
	person.getAddressList().add(new ValidAddress());
	BeanPropertyBindingResult result = new BeanPropertyBindingResult(person, "person");
	validator.validate(person, result);
	assertEquals(3, result.getErrorCount());
	FieldError fieldError = result.getFieldError("name");
	assertEquals("name", fieldError.getField());
	fieldError = result.getFieldError("address.street");
	assertEquals("address.street", fieldError.getField());
	fieldError = result.getFieldError("addressList[0].street");
	assertEquals("addressList[0].street", fieldError.getField());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:17,代碼來源:ValidatorFactoryTests.java

示例9: testSpringValidationWithErrorInSetElement

import org.springframework.validation.BeanPropertyBindingResult; //導入依賴的package包/類
@Test
public void testSpringValidationWithErrorInSetElement() throws Exception {
	LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
	validator.afterPropertiesSet();
	ValidPerson person = new ValidPerson();
	person.getAddressSet().add(new ValidAddress());
	BeanPropertyBindingResult result = new BeanPropertyBindingResult(person, "person");
	validator.validate(person, result);
	assertEquals(3, result.getErrorCount());
	FieldError fieldError = result.getFieldError("name");
	assertEquals("name", fieldError.getField());
	fieldError = result.getFieldError("address.street");
	assertEquals("address.street", fieldError.getField());
	fieldError = result.getFieldError("addressSet[].street");
	assertEquals("addressSet[].street", fieldError.getField());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:17,代碼來源:ValidatorFactoryTests.java

示例10: renderNoModelKeyAndBindingResultFirst

import org.springframework.validation.BeanPropertyBindingResult; //導入依賴的package包/類
@Test
public void renderNoModelKeyAndBindingResultFirst() throws Exception {
	Object toBeMarshalled = new Object();
	String modelKey = "key";
	Map<String, Object> model = new LinkedHashMap<String, Object>();
	model.put(BindingResult.MODEL_KEY_PREFIX + modelKey, new BeanPropertyBindingResult(toBeMarshalled, modelKey));
	model.put(modelKey, toBeMarshalled);

	MockHttpServletRequest request = new MockHttpServletRequest();
	MockHttpServletResponse response = new MockHttpServletResponse();

	given(marshallerMock.supports(BeanPropertyBindingResult.class)).willReturn(true);
	given(marshallerMock.supports(Object.class)).willReturn(true);

	view.render(model, request, response);
	assertEquals("Invalid content type", "application/xml", response.getContentType());
	assertEquals("Invalid content length", 0, response.getContentLength());
	verify(marshallerMock).marshal(eq(toBeMarshalled), isA(StreamResult.class));
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:20,代碼來源:MarshallingViewTests.java

示例11: withErrors

import org.springframework.validation.BeanPropertyBindingResult; //導入依賴的package包/類
@Test
public void withErrors() throws Exception {
	this.tag.setPath("name");
	this.tag.setCssClass("good");
	this.tag.setCssErrorClass("bad");

	BeanPropertyBindingResult errors = new BeanPropertyBindingResult(this.rob, COMMAND_NAME);
	errors.rejectValue("name", "some.code", "Default Message");
	errors.rejectValue("name", "too.short", "Too Short");
	exposeBindingResult(errors);

	assertEquals(Tag.SKIP_BODY, this.tag.doStartTag());

	String output = getOutput();
	assertTagOpened(output);
	assertTagClosed(output);

	assertContainsAttribute(output, "type", getType());
	assertValueAttribute(output, "Rob");
	assertContainsAttribute(output, "class", "bad");
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:22,代碼來源:InputTagTests.java

示例12: withCustomBinder

import org.springframework.validation.BeanPropertyBindingResult; //導入依賴的package包/類
@Test
public void withCustomBinder() throws Exception {
	this.tag.setPath("myFloat");

	BeanPropertyBindingResult errors = new BeanPropertyBindingResult(this.rob, COMMAND_NAME);
	errors.getPropertyAccessor().registerCustomEditor(Float.class, new SimpleFloatEditor());
	exposeBindingResult(errors);

	assertEquals(Tag.SKIP_BODY, this.tag.doStartTag());

	String output = getOutput();
	assertTagOpened(output);
	assertTagClosed(output);

	assertContainsAttribute(output, "type", getType());
	assertValueAttribute(output, "12.34f");
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:18,代碼來源:InputTagTests.java

示例13: withCheckedObjectValueAndEditor

import org.springframework.validation.BeanPropertyBindingResult; //導入依賴的package包/類
@Test
public void withCheckedObjectValueAndEditor() throws Exception {
	this.tag.setPath("myFloat");
	this.tag.setValue("F12.99");

	BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(this.bean, COMMAND_NAME);
	MyFloatEditor editor = new MyFloatEditor();
	bindingResult.getPropertyEditorRegistry().registerCustomEditor(Float.class, editor);
	getPageContext().getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + COMMAND_NAME, bindingResult);

	int result = this.tag.doStartTag();
	assertEquals(Tag.SKIP_BODY, result);

	String output = getOutput();
	assertTagOpened(output);
	assertTagClosed(output);
	assertContainsAttribute(output, "name", "myFloat");
	assertContainsAttribute(output, "type", "radio");
	assertContainsAttribute(output, "value", "F" + getFloat().toString());
	assertContainsAttribute(output, "checked", "checked");
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:22,代碼來源:RadioButtonTagTests.java

示例14: withCustomBinder

import org.springframework.validation.BeanPropertyBindingResult; //導入依賴的package包/類
@Test
public void withCustomBinder() throws Exception {
	this.tag.setPath("myFloat");

	BeanPropertyBindingResult errors = new BeanPropertyBindingResult(this.bean, COMMAND_NAME);
	errors.getPropertyAccessor().registerCustomEditor(Float.class, new SimpleFloatEditor());
	exposeBindingResult(errors);

	assertEquals(Tag.SKIP_BODY, this.tag.doStartTag());

	String output = getOutput();

	assertTagOpened(output);
	assertTagClosed(output);

	assertContainsAttribute(output, "type", "hidden");
	assertContainsAttribute(output, "value", "12.34f");
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:19,代碼來源:HiddenInputTagTests.java

示例15: withExplicitNonWhitespaceBodyContent

import org.springframework.validation.BeanPropertyBindingResult; //導入依賴的package包/類
@Test
public void withExplicitNonWhitespaceBodyContent() throws Exception {
	String mockContent = "This is some explicit body content";
	this.tag.setBodyContent(new MockBodyContent(mockContent, getWriter()));

	// construct an errors instance of the tag
	TestBean target = new TestBean();
	target.setName("Rob Harrop");
	Errors errors = new BeanPropertyBindingResult(target, COMMAND_NAME);
	errors.rejectValue("name", "some.code", "Default Message");

	exposeBindingResult(errors);

	int result = this.tag.doStartTag();
	assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);

	result = this.tag.doEndTag();
	assertEquals(Tag.EVAL_PAGE, result);
	assertEquals(mockContent, getOutput());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:21,代碼來源:ErrorsTagTests.java


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