Example usage for org.apache.commons.validator Validator setUseContextClassLoader

List of usage examples for org.apache.commons.validator Validator setUseContextClassLoader

Introduction

In this page you can find the example usage for org.apache.commons.validator Validator setUseContextClassLoader.

Prototype

public void setUseContextClassLoader(boolean use) 

Source Link

Document

Determine whether to use the Context ClassLoader (the one found by calling Thread.currentThread().getContextClassLoader()) to resolve/load classes that are defined in various rules.

Usage

From source file:org.apache.struts.validator.Resources.java

/**
 * Initialize the <code>Validator</code> to perform validation.
 *
 * @param key         The key that the validation rules are under (the
 *                    form elements name attribute).
 * @param bean        The bean validation is being performed on.
 * @param application servlet context//from w  w w . j a va  2 s  . c o  m
 * @param request     The current request object.
 * @param errors      The object any errors will be stored in.
 * @param page        This in conjunction with  the page property of a
 *                    <code>Field<code> can control the processing of
 *                    fields.  If the field's page is less than or equal
 *                    to this page value, it will be processed.
 */
public static Validator initValidator(String key, Object bean, ServletContext application,
        HttpServletRequest request, ActionMessages errors, int page) {
    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;
}