Package org.springframework.validation.beanvalidation

Examples of org.springframework.validation.beanvalidation.LocalValidatorFactoryBean


    assertNull(rejected);
  }

  @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");
    assertNull(rejected);
  }
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

    @SuppressWarnings("unused")
    @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

      extends MyCommandProvidingFormController<String, TestBean, ITestBean> {

    @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

  static class MyWebBindingInitializer implements WebBindingInitializer {

    @Override
    public void initBinder(WebDataBinder binder, WebRequest request) {
      LocalValidatorFactoryBean vf = new LocalValidatorFactoryBean();
      vf.afterPropertiesSet();
      binder.setValidator(vf);
      assertNotNull(request.getLocale());
      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
    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

      extends MyCommandProvidingFormController {

    @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

  private static class MyWebBindingInitializer implements WebBindingInitializer {

    @Override
    public void initBinder(WebDataBinder binder, WebRequest request) {
      LocalValidatorFactoryBean vf = new LocalValidatorFactoryBean();
      vf.afterPropertiesSet();
      binder.setValidator(vf);
      assertNotNull(request.getLocale());
      SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
      dateFormat.setLenient(false);
      binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false));
View Full Code Here

  }

  @Bean
  @Scope(value = BeanDefinition.SCOPE_SINGLETON)
  public ValidatorFactory validatorFactory() {
    return new LocalValidatorFactoryBean();
  }
View Full Code Here

TOP

Related Classes of org.springframework.validation.beanvalidation.LocalValidatorFactoryBean

Copyright © 2018 www.massapicom. 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.