Package org.springframework.validation

Examples of org.springframework.validation.Validator


            new ClassPathXmlApplicationContext("org/springmodules/validation/bean/beanValidator-tests.xml");

        Person person = new Person("Uri");
        BindException errors = new BindException(person, "person");

        Validator validator = (Validator)context.getBean("validator");
        validator.validate(person, errors);

        assertTrue(errors.hasGlobalErrors());
        assertEquals(1, errors.getGlobalErrorCount());
        assertEquals("Person[bad]", errors.getGlobalError().getCode());
View Full Code Here


        Person person = new Person("Uri");
        person.setPhone("1234"); // should be validation error - length < 7
        BindException errors = new BindException(person, "person");

        Validator validator = (Validator)context.getBean("validator");
        validator.validate(person, errors);

        assertTrue(errors.hasFieldErrors("phone"));
        assertEquals(1, errors.getFieldErrorCount("phone"));
        assertEquals("Person.phone[min.length]", errors.getFieldError("phone").getCode());
    }
View Full Code Here

    }

    protected void validatePage(Object command, Errors errors, int page) {
        Validator[] validators = getValidators();
        for (int i=0; i<validators.length; i++) {
            Validator validator = validators[i];
            if (validator instanceof PageAware) {
                if (((PageAware)validator).getPage() == page) {
                    validator.validate(command, errors);
                }
            }
        }
    }
View Full Code Here

  /**
   * Verify that the handler works correctly (i.e. no-op) with a
   * {@link org.springframework.validation.Validator native} validator.
   */
  public void testWithNonValangValidators() throws Exception {
    Validator plainValidator = new Validator() {
      public boolean supports(Class arg0) {
        return false;
      }

      public void validate(Object arg0, Errors arg1) {
View Full Code Here

        }
    }

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

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

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

    }
View Full Code Here

        if (applicationContext == null) {
            throw new UnsupportedOperationException(VALIDATOR_BEAN_TAG + " configuration cannot be applied for " +
                "this configuration loader was not deployed in an application context");
        }
        String beanName = definition.getAttribute(NAME_ATTR);
        Validator validator = (Validator)applicationContext.getBean(beanName, Validator.class);
        configuration.addCustomValidator(validator);
    }
View Full Code Here

    public void testApplyCustomValidator() throws Exception {
        Object object = new Object();

        MockControl customValidatorControl = MockControl.createControl(Validator.class);
        Validator customValidator = (Validator) customValidatorControl.getMock();
        customValidator.validate(object, errors);
        configurationControl.expectAndReturn(configuration.getCustomValidator(), customValidator);

        replay();
        validator.applyCustomValidator(configuration, object, errors);
        verify();
View Full Code Here

     *             if the controller's validator is not an instance of
     *             {@link org.springmodules.validation.valang.ValangValidator}
     */
    public static void addValangRulesToModel(BaseCommandController controller, Map model) {
        Assert.hasText(controller.getCommandName(), "controller must define a command name");
        Validator validator = controller.getValidator();
        Assert.isInstanceOf(ValangValidator.class, validator, "controller's validator of class '"
                + (validator != null ? validator.getClass().getName() : "[null]")
                + "' must be an instance of 'ValangValidator'");
        ValangValidator vv = (ValangValidator) validator;
        addValangRulesToModel(controller.getCommandName(), vv.getRules(), model);
    }
View Full Code Here

            new ClassPathXmlApplicationContext("org/springmodules/validation/bean/beanValidator-tests.xml");

        Person person = new Person("Uri");
        BindException errors = new BindException(person, "person");

        Validator validator = (Validator) context.getBean("validator");
        validator.validate(person, errors);

        assertTrue(errors.hasGlobalErrors());
        assertEquals(1, errors.getGlobalErrorCount());
        assertEquals("Person[bad]", errors.getGlobalError().getCode());
View Full Code Here

        Person person = new Person("Uri");
        person.setPhone("1234"); // should be validation error - length < 7
        BindException errors = new BindException(person, "person");

        Validator validator = (Validator) context.getBean("validator");
        validator.validate(person, errors);

        assertTrue(errors.hasFieldErrors("phone"));
        assertEquals(1, errors.getFieldErrorCount("phone"));
        assertEquals("Person.phone[min.length]", errors.getFieldError("phone").getCode());
    }
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.