Package org.apache.commons.validator

Examples of org.apache.commons.validator.Validator


    }

    private Validator getCommonsValidator() {
        ValidatorResources res = new ValidatorResources();
        res.process();
        return new Validator(res);
    }
View Full Code Here


    }

    private Validator getCommonsValidator() {
        ValidatorResources res = new ValidatorResources();
        res.process();
        return new Validator(res);
    }
View Full Code Here

        if (validatorFormName == null)
        {
            return result; // no validation for this bean
        }

        Validator validator = new Validator(validations, validatorFormName);

        // Tell the validator which bean to validate against.
        validator.setParameter(Validator.BEAN_PARAM, bean);
       
        // Parameters used by our validators
        validator.setParameter("java.util.Map", result);
        validator.setParameter("java.util.ResourceBundle", bundle);
       
        ValidatorResults results = null;
               
        try
        {
            validator.setOnlyReturnErrors(true);
            results = validator.validate();
            if (results.isEmpty())
            {
                return result;
            }
        }
View Full Code Here

        if (validatorFormName == null)
        {
            return result; // no validation for this bean
        }

        Validator validator = new Validator(validations, validatorFormName);

        // Tell the validator which bean to validate against.
        validator.setParameter(Validator.BEAN_PARAM, bean);
       
        // Parameters used by our validators
        validator.setParameter("java.util.Map", result);
        validator.setParameter("java.util.ResourceBundle", bundle);
       
        ValidatorResults results = null;
               
        try
        {
            validator.setOnlyReturnErrors(true);
            results = validator.validate();
            if (results.isEmpty())
            {
                return result;
            }
        }
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.addResource(Validator.BEAN_KEY, 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 everything should pass.
            bean.setAge("123");
            results = validator.validate();
            printResults(bean, results, resources);

        } finally {
            // Make sure we close the input stream if it was left open.
            if (in != null) {
View Full Code Here

     *
     * @param beanName The name of the bean for which this <code>Validator</code> will be created
     * @see org.apache.commons.validator.Validator
     */
    public Validator getValidator(String beanName, Object bean, Errors errors) {
        Validator validator = new Validator(validatorResources, beanName);
        validator.setParameter(DefaultValidatorFactory.ERRORS_KEY, errors);
        validator.setParameter(Validator.BEAN_PARAM, bean);
        return validator;
    }
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

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.