Package org.springframework.validation.beanvalidation

Examples of org.springframework.validation.beanvalidation.LocalValidatorFactoryBean.afterPropertiesSet()


  }

  @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");
View Full Code Here


  }

  @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);
View Full Code Here

  }

  @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());
View Full Code Here

  }

  @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());
View Full Code Here

  }

  @Test
  public void testInnerBeanValidation() throws Exception {
    LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
    validator.afterPropertiesSet();

    MainBean mainBean = new MainBean();
    Errors errors = new BeanPropertyBindingResult(mainBean, "mainBean");
    validator.validate(mainBean, errors);
    Object rejected = errors.getFieldValue("inner.value");
View Full Code Here

  }

  @Test
  public void testValidationWithOptionalField() throws Exception {
    LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
    validator.afterPropertiesSet();

    MainBeanWithOptional mainBean = new MainBeanWithOptional();
    Errors errors = new BeanPropertyBindingResult(mainBean, "mainBean");
    validator.validate(mainBean, errors);
    Object rejected = errors.getFieldValue("inner.value");
View Full Code Here

  private final class ValidatingBinderFactory implements WebDataBinderFactory {
    @Override
    public WebDataBinder createBinder(NativeWebRequest webRequest, Object target, String objectName) throws Exception {
      LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
      validator.afterPropertiesSet();
      WebDataBinder dataBinder = new WebDataBinder(target, objectName);
      dataBinder.setValidator(validator);
      return dataBinder;
    }
  }
View Full Code Here

  private final class ValidatingBinderFactory implements WebDataBinderFactory {
    @Override
    public WebDataBinder createBinder(NativeWebRequest webRequest, Object target, String objectName) throws Exception {
      LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
      validator.afterPropertiesSet();
      WebDataBinder dataBinder = new WebDataBinder(target, objectName);
      dataBinder.setValidator(validator);
      return dataBinder;
    }
  }
View Full Code Here

    @InitBinder
    private void initBinder(WebDataBinder binder) {
      binder.initBeanPropertyAccess();
      binder.setRequiredFields("sex");
      LocalValidatorFactoryBean vf = new LocalValidatorFactoryBean();
      vf.afterPropertiesSet();
      binder.setValidator(vf);
      SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
      dateFormat.setLenient(false);
      binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false));
    }
View Full Code Here

    @SuppressWarnings("unused")
    @InitBinder({"myCommand", "date"})
    private void initBinder(WebDataBinder binder, String date, @RequestParam("date") String[] date2) {
      LocalValidatorFactoryBean vf = new LocalValidatorFactoryBean();
      vf.afterPropertiesSet();
      binder.setValidator(vf);
      assertEquals("2007-10-02", date);
      assertEquals(1, date2.length);
      assertEquals("2007-10-02", date2[0]);
      SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.