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

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

Introduction

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

Prototype

String LOCALE_PARAM

To view the source code for org.apache.commons.validator Validator LOCALE_PARAM.

Click Source Link

Document

Resources key the Locale is stored.

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 ww w .j av  a2  s  .  c  om
 * @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;
}