Package org.springframework.validation

Examples of org.springframework.validation.BindException


        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());
        assertTrue(lifeCycleBean.isResourceLoaderSet());

        assertTrue(errors.hasFieldErrors("firstName"));
    }
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

        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

        validator.setValang("{ firstName : tupper(?) == 'FN' : 'First name is empty' }");
        validator.afterPropertiesSet();

        Person person = new Person();
        person.setFirstName("fn");
        BindException errors = new BindException(person, "person");
        validator.validate(person, errors);

        assertFalse(errors.hasErrors());
    }
View Full Code Here

        }
    }

    private boolean validate(Object target, String text) {
        Collection rules = parseRules(text);
        Errors errors = new BindException(target, "person");

        Object tmpTarget = null;
        if (!(target instanceof Map)) {
            tmpTarget = new BeanWrapperImpl(target);
        } else {
            tmpTarget = target;
        }
        for (Iterator iter = rules.iterator(); iter.hasNext();) {
            ValidationRule rule = (ValidationRule) iter.next();
            rule.validate(tmpTarget, errors);
        }
        return !errors.hasErrors();
    }
View Full Code Here

    public void testValidate_WithMappedProperty_Failure() throws Exception {
        FooBean bean = new FooBean();
        Map attributes = new HashMap();
        bean.setAttributes(attributes);

        BindException errors = new BindException(bean, "fooBeanWithMappedProperty");

        ConfigurableBeanValidator validator = getValidator("fooBeanWithMappedProperty");
        validator.validate(bean, errors);

        assertTrue(errors.hasFieldErrors("attributes[name1]"));
    }
View Full Code Here

        FooBean bean = new FooBean();
        Map attributes = new HashMap();
        attributes.put("name1", "value1");
        bean.setAttributes(attributes);

        BindException errors = new BindException(bean, "fooBeanWithMappedProperty");

        ConfigurableBeanValidator validator = getValidator("fooBeanWithMappedProperty");
        validator.validate(bean, errors);

        assertFalse(errors.hasFieldErrors("attributes[name1]"));
    }
View Full Code Here

        person.setAge(-1);
        person.setEmail("uri@b");
        person.setPassword("pa");
        person.setConfirmPassword("pa1");

        BindException errors = new BindException(person, "person");
        validator.validate(person, errors);

        assertEquals(1, errors.getGlobalErrorCount());
        assertEquals(3, errors.getFieldErrorCount());

    }
View Full Code Here

        person.setAge(-1);
        person.setEmail("uri@b");
        person.setPassword("pa");
        person.setConfirmPassword("pa1");

        BindException errors = new BindException(person, "person");
        validator.validate(person, errors);

        assertEquals(1, errors.getGlobalErrorCount());

        // testing the test error code converter
        String[] codes = errors.getGlobalError().getCodes();
        assertTrue(ArrayUtils.contains(codes, "test.passwords.do.not.match"));

        assertEquals(4, errors.getFieldErrorCount());

    }
View Full Code Here

        person.setAge(-1);
        person.setEmail("uri@b");
        person.setPassword("pa");
        person.setConfirmPassword("pa1");

        BindException errors = new BindException(person, "person");
        validator2.validate(person, errors);

        assertEquals(1, errors.getGlobalErrorCount());

        // testing the test error code converter
        String[] codes = errors.getGlobalError().getCodes();
        assertTrue(ArrayUtils.contains(codes, "test.passwords.do.not.match"));

        assertEquals(4, errors.getFieldErrorCount());

    }
View Full Code Here

TOP

Related Classes of org.springframework.validation.BindException

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.