Package org.apache.commons.validator

Examples of org.apache.commons.validator.Validator


        ServletContext application = getServlet().getServletContext();
        ActionErrors errors = new ActionErrors();

        String validationKey = getValidationKey(mapping, request);

        Validator validator = Resources.initValidator(validationKey,
                             this,
                             application, request,
                             errors, page);

        try {
            validatorResults = validator.validate();
        } catch (ValidatorException e) {
            log.error(e.getMessage(), e);
        }

        return errors;
View Full Code Here


        ServletContext application = getServlet().getServletContext();
        ActionErrors errors = new ActionErrors();

        String validationKey = getValidationKey(mapping, request);

        Validator validator = Resources.initValidator(validationKey,
                             this,
                             application, request,
                             errors, page);

        try {
            validatorResults = validator.validate();
        } catch (ValidatorException e) {
            log.error(e.getMessage(), e);
        }

        return errors;
View Full Code Here

            try
            {
                //
                // Run validations associated with the bean.
                //
                Validator beanV = initValidator( beanName, bean, servletContext, request, errors, page );
                validatorResults = beanV.validate();

                //
                // Run validations associated with the action.
                //
                Validator actionV = initValidator( mapping.getPath(), bean, servletContext, request, errors, page );
                validatorResults.merge( actionV.validate() );
            }
            catch ( ValidatorException e )
            {
                _log.error( e.getMessage(), e );
            }
View Full Code Here

        if ( _legacyInitValidatorMethod != null )
        {
            try
            {
                Object[] args = new Object[]{ beanName, bean, context, request, errors, new Integer( page ) };
                Validator validator = ( Validator ) _legacyInitValidatorMethod.invoke( Resources.class, args );

                //
                // The NetUI validator rules work on both 1.1 and 1.2.  They take ActionMessages instead of ActionErrors.
                //
                validator.addResource( "org.apache.struts.action.ActionMessages", errors );
                return validator;
            }
            catch ( IllegalAccessException e )
            {
                assert false : e.getMessage();
View Full Code Here

        // Create a test bean to validate against.
        ValidateBean bean = new ValidateBean();
       
        // Create a validator with the ValidateBean actions for the bean
        // we're interested in.
        Validator validator = new Validator(resources, "ValidateBean");
       
        // Tell the validator which bean to validate against.
        validator.setParameter(Validator.BEAN_PARAM, bean);
       
        ValidatorResults results = null;
       
        // Run the validation actions against the bean.  Since all of the properties
        // are null, we expect them all to error out except for street2, which has
        // no validations (it's an optional property)
       
        results = validator.validate();
        printResults(bean, results, resources);
       
        // Now set all the required properties, but make the age a non-integer.
        // You'll notice that age will pass the required test, but fail the int
        // test.
        bean.setLastName("Tester");
        bean.setFirstName("John");
        bean.setStreet1("1 Test Street");
        bean.setCity("Testville");
        bean.setState("TE");
        bean.setPostalCode("12345");
        bean.setAge("Too Old");
        results = validator.validate();
        printResults(bean, results, resources);
       
        // Now only report failed fields
        validator.setOnlyReturnErrors(true);
        results = validator.validate();
        printResults(bean, results, resources);
       
        // Now everything should pass.
        validator.setOnlyReturnErrors(false);
        bean.setAge("123");
        results = validator.validate();
        printResults(bean, results, resources);
    }
View Full Code Here

        // Create a test bean to validate against.
        ValidateBean bean = new ValidateBean();
       
        // Create a validator with the ValidateBean actions for the bean
        // we're interested in.
        Validator validator = new Validator(resources, "ValidateBean");
       
        // Tell the validator which bean to validate against.
        validator.setParameter(Validator.BEAN_PARAM, bean);
       
        ValidatorResults results = null;
       
        // Run the validation actions against the bean.  Since all of the properties
        // are null, we expect them all to error out except for street2, which has
        // no validations (it's an optional property)
       
        results = validator.validate();
        printResults(bean, results, resources);
       
        // Now set all the required properties, but make the age a non-integer.
        // You'll notice that age will pass the required test, but fail the int
        // test.
        bean.setLastName("Tester");
        bean.setFirstName("John");
        bean.setStreet1("1 Test Street");
        bean.setCity("Testville");
        bean.setState("TE");
        bean.setPostalCode("12345");
        bean.setAge("Too Old");
        results = validator.validate();
        printResults(bean, results, resources);
       
        // Now only report failed fields
        validator.setOnlyReturnErrors(true);
        results = validator.validate();
        printResults(bean, results, resources);
       
        // Now everything should pass.
        validator.setOnlyReturnErrors(false);
        bean.setAge("123");
        results = validator.validate();
        printResults(bean, results, resources);
    }
View Full Code Here

        ServletContext application = getServlet().getServletContext();
        ActionErrors errors = new ActionErrors();

        String validationKey = getValidationKey(mapping, request);

        Validator validator = Resources.initValidator(validationKey,
                             this,
                             application, request,
                             errors, page);

        try {
            validatorResults = validator.validate();
        } catch (ValidatorException e) {
            log.error(e.getMessage(), e);
        }

        return errors;
View Full Code Here

        ServletContext application = getServlet().getServletContext();
        ActionErrors errors = new ActionErrors();

        String validationKey = getValidationKey(mapping, request);

        Validator validator = Resources.initValidator(validationKey,
                             this,
                             application, request,
                             errors, page);

        try {
            validatorResults = validator.validate();
        } catch (ValidatorException e) {
            log.error(e.getMessage(), e);
        }

        return errors;
View Full Code Here

        ValidatorResources resources =
            Resources.getValidatorResources(application, request);

        Locale locale = RequestUtils.getUserLocale(request, null);

        Validator validator = new Validator(resources, key);
        validator.setUseContextClassLoader(true);

        validator.setPage(page);

        validator.setParameter(SERVLET_CONTEXT_PARAM, application);
        validator.setParameter(HTTP_SERVLET_REQUEST_PARAM, request);
        validator.setParameter(Validator.LOCALE_PARAM, locale);
        validator.setParameter(ACTION_MESSAGES_PARAM, errors);
        validator.setParameter(Validator.BEAN_PARAM, bean);

        return validator;
    }
View Full Code Here

        // Create a test bean to validate against.
        ValidateBean bean = new ValidateBean();
       
        // Create a validator with the ValidateBean actions for the bean
        // we're interested in.
        Validator validator = new Validator(resources, "ValidateBean");
       
        // Tell the validator which bean to validate against.
        validator.setParameter(Validator.BEAN_PARAM, bean);
       
        ValidatorResults results = null;
       
        // Run the validation actions against the bean.  Since all of the properties
        // are null, we expect them all to error out except for street2, which has
        // no validations (it's an optional property)
       
        results = validator.validate();
        printResults(bean, results, resources);
       
        // Now set all the required properties, but make the age a non-integer.
        // You'll notice that age will pass the required test, but fail the int
        // test.
        bean.setLastName("Tester");
        bean.setFirstName("John");
        bean.setStreet1("1 Test Street");
        bean.setCity("Testville");
        bean.setState("TE");
        bean.setPostalCode("12345");
        bean.setAge("Too Old");
        results = validator.validate();
        printResults(bean, results, resources);
       
        // Now only report failed fields
        validator.setOnlyReturnErrors(true);
        results = validator.validate();
        printResults(bean, results, resources);
       
        // Now everything should pass.
        validator.setOnlyReturnErrors(false);
        bean.setAge("123");
        results = validator.validate();
        printResults(bean, results, resources);
    }
View Full Code Here

TOP

Related Classes of org.apache.commons.validator.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.