org.springframework.validation.BindException.getErrorCount()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(4.2k)|赞(0)|评价(0)|浏览(135)

本文整理了Java中org.springframework.validation.BindException.getErrorCount()方法的一些代码示例,展示了BindException.getErrorCount()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BindException.getErrorCount()方法的具体详情如下:
包路径:org.springframework.validation.BindException
类名称:BindException
方法名:getErrorCount

BindException.getErrorCount介绍

暂无

代码示例

代码示例来源:origin: spring-projects/spring-batch

@Test
public void testBinderWithErrors() throws Exception {
  BeanWrapperFieldSetMapper<TestObject> mapper = new BeanWrapperFieldSetMapper<>();
  mapper.setTargetType(TestObject.class);
  FieldSet fieldSet = new DefaultFieldSet(new String[] { "foo", "7890.1" }, new String[] { "varDouble",
      "varFloat" });
  try {
    mapper.mapFieldSet(fieldSet);
    fail("Expected BindException");
  }
  catch (BindException e) {
    assertEquals(1, e.getErrorCount());
    assertEquals("typeMismatch", e.getFieldError("varDouble").getCode());
  }
}

代码示例来源:origin: org.sakaiproject.metaobj/sakai-metaobj-tool-lib

logger.debug("Form submission errors: " + errors.getErrorCount());
HttpServletHelper.getInstance().reloadApplicationMap(request, application);
HttpServletHelper.getInstance().reloadSessionMap(request, session);

代码示例来源:origin: org.springframework/spring-webflow

/**
 * Bind allowed parameters in the external context request parameter map to the form object using given binder.
 * @param context the action execution context, for accessing and setting data in "flow scope" or "request scope"
 * @param binder the data binder to use
 * @throws Exception when an unrecoverable exception occurs
 */
protected void doBind(RequestContext context, DataBinder binder) throws Exception {
  if (logger.isDebugEnabled()) {
    logger.debug("Binding allowed request parameters in "
        + StylerUtils.style(context.getExternalContext().getRequestParameterMap())
        + " to form object with name '" + binder.getObjectName() + "', pre-bind formObject toString = "
        + binder.getTarget());
    if (binder.getAllowedFields() != null && binder.getAllowedFields().length > 0) {
      logger.debug("(Allowed fields are " + StylerUtils.style(binder.getAllowedFields()) + ")");
    } else {
      logger.debug("(Any field is allowed)");
    }
  }
  binder.bind(new MutablePropertyValues(context.getRequestParameters().asMap()));
  if (logger.isDebugEnabled()) {
    logger.debug("Binding completed for form object with name '" + binder.getObjectName()
        + "', post-bind formObject toString = " + binder.getTarget());
    logger.debug("There are [" + binder.getErrors().getErrorCount() + "] errors, details: "
        + binder.getErrors().getAllErrors());
  }
}

代码示例来源:origin: org.springframework/org.springframework.web.portlet

logger.debug("Data binding errors: " + errors.getErrorCount());

代码示例来源:origin: v5developer/maven-framework-project

@Test
public void product_with_existing_productId_invalid() {
  //Arrange
  Product product = new Product("P1234","iPhone 5s", new BigDecimal(500));
  product.setCategory("Tablet");
  
  BindException bindException = new BindException(product, " product");
  //Act
  ValidationUtils.invokeValidator(productValidator, product, bindException);
  
  //Assert
  Assert.assertEquals(1, bindException.getErrorCount()); 
  Assert.assertTrue(bindException.getLocalizedMessage().contains("A product already exists with this product id."));
}

代码示例来源:origin: v5developer/maven-framework-project

@Test
public void a_valid_product_should_not_get_any_error_during_validation() {
  //Arrange
  Product product = new Product("P9876","iPhone 5s", new BigDecimal(500));
  product.setCategory("Tablet");
  
  BindException bindException = new BindException(product, " product");
  //Act
  ValidationUtils.invokeValidator(productValidator, product, bindException);
  
  //Assert
  Assert.assertEquals(0, bindException.getErrorCount()); 
}

代码示例来源:origin: v5developer/maven-framework-project

@Test
public void product_without_UnitPrice_should_be_invalid() {
  //Arrange
  Product product = new Product();
  BindException bindException = new BindException(product, " product");
  //Act
  ValidationUtils.invokeValidator(productValidator, product, bindException);
  
  //Assert
  Assert.assertEquals(1, bindException.getErrorCount()); 
  Assert.assertTrue(bindException.getLocalizedMessage().contains("Unit price is Invalid. It cannot be empty."));
}

相关文章