Package org.springframework.validation

Examples of org.springframework.validation.Validator


    }

    public void testValidatorRef_WhenDeployedInApplicationContext() throws Exception {
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("appCtxt.xml", getClass());
        Validator validator = (Validator)context.getBean("validator");

        TeztBean1 bean = new TeztBean1();
        BindException errors = new BindException(bean, "bean");
        validator.validate(bean, errors);
        assertTrue(errors.hasErrors());
        assertTrue(errors.hasFieldErrors("name"));

        bean = new TeztBean1("test");
        errors = new BindException(bean, "bean");
        validator.validate(bean, errors);
        assertFalse(errors.hasErrors());

    }
View Full Code Here


  public final void setValidators(Map validators) {
    for (Iterator iter = validators.keySet().iterator(); iter.hasNext();) {
      Object key = iter.next();
      Object value = validators.get(key);
      Class clazz = null;
      Validator validator = null;
     
      if (value != null) {
        if (value instanceof Validator) {
          validator = (Validator)value;
        } else {
View Full Code Here

        LifeCycleBean lifeCycleBean = new LifeCycleBean();
        Person person = new Person();
        person.setLifeCycleBean(lifeCycleBean);
        person.setFirstName("FN");

        Validator validator = (Validator) appCtx.getBean("testCustomFunctions");
        BindException errors = new BindException(person, "person");
        validator.validate(person, errors);

        assertTrue(lifeCycleBean.isApplicationContextSet());
        assertTrue(lifeCycleBean.isApplicationEventPublisher());
        assertTrue(lifeCycleBean.isBeanFactorySet());
        assertTrue(lifeCycleBean.isMessageSourceSet());
View Full Code Here

        LifeCycleBean lifeCycleBean = new LifeCycleBean();
        Person person = new Person();
        person.setLifeCycleBean(lifeCycleBean);
        person.setFirstName("FN");

        Validator validator = (Validator) appCtx.getBean("testCustomFunctionsFromApplicationContext");
        BindException errors = new BindException(person, "person");
        validator.validate(person, errors);

        assertTrue(lifeCycleBean.isApplicationContextSet());
        assertTrue(lifeCycleBean.isApplicationEventPublisher());
        assertTrue(lifeCycleBean.isBeanFactorySet());
        assertTrue(lifeCycleBean.isMessageSourceSet());
View Full Code Here

        Person person = new Person();
        person.setFirstName("FN");
        person.setFirstName("LN");

        Validator validator = (Validator) appCtx.getBean("testFunctionFromApplicationContext");
        BindException errors = new BindException(person, "person");
        validator.validate(person, errors);

        assertTrue(errors.hasFieldErrors("firstName"));
    }
View Full Code Here

        assertTrue(errors.hasFieldErrors("firstName"));
    }

    public void testPersonValidator() {
        Validator validator = (Validator) appCtx.getBean("personValidator", Validator.class);
        Person person = new Person();
        Map map = new HashMap();
        map.put("name", "Steven");
        map.put("passwd", "pas");
        person.setForm(map);
        Errors errors = new BindException(person, "person");
        validator.validate(person, errors);

        assertFalse(errors.hasFieldErrors("form[name]"));
        assertTrue(errors.hasFieldErrors("form[passwd]"));
    }
View Full Code Here

     * @param configuration The configuration from which the custom validator will be taken from.
     * @param obj The object to be validated.
     * @param errors The {@link Errors} instance where all validation errors will be registered.
     */
    protected void applyCustomValidator(BeanValidationConfiguration configuration, Object obj, Errors errors) {
        Validator validator = configuration.getCustomValidator();
        if (validator != null) {
            if (validator.supports(obj.getClass())) {
                validator.validate(obj, errors);
            }
        }
    }
View Full Code Here

     * @return Whether this validator supports the given class.
     * @see Validator#supports(Class)
     */
    public boolean supports(Class clazz) {
        for (Iterator i = validators.iterator(); i.hasNext();) {
            Validator validator = (Validator) i.next();
            if (validator.supports(clazz)) {
                return true;
            }
        }
        return false;
    }
View Full Code Here

     * @param errors A registry where validation errors are registered.
     * @see Validator#validate(Object, org.springframework.validation.Errors)
     */
    public void validate(Object obj, Errors errors) {
        for (Iterator i = validators.iterator(); i.hasNext();) {
            Validator validator = (Validator) i.next();
            if (validator.supports(obj.getClass())) {
                validator.validate(obj, errors);
            }
        }
    }
View Full Code Here

    Map validatorsMap = getValidators(event);
    Class clazz = target.getClass();
   
    for (Iterator iter = validatorsMap.keySet().iterator(); iter.hasNext();) {
      Class tmpClazz = (Class)iter.next();
      Validator validator = (Validator)validatorsMap.get(tmpClazz);
     
      if (tmpClazz.isAssignableFrom(clazz)) {
        validator.validate(target, errors);
      }
    }   
  }
View Full Code Here

TOP

Related Classes of org.springframework.validation.Validator

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.