Example usage for org.apache.commons.validator GenericTypeValidator formatLong

List of usage examples for org.apache.commons.validator GenericTypeValidator formatLong

Introduction

In this page you can find the example usage for org.apache.commons.validator GenericTypeValidator formatLong.

Prototype

public static Long formatLong(String value, Locale locale) 

Source Link

Document

Checks if the value can safely be converted to a long primitive.

Usage

From source file:com.core.validators.CommonValidator.java

/**
 * Checks if the field can be successfully converted to a <code>long</code>.
 *
 * @param value The value validation is being performed on.
 * @return boolean If the field can be successfully converted 
 * to a <code>long</code> <code>true</code> is returned.  
 * Otherwise <code>false</code>.
 *//*  ww  w.  ja  v  a2  s  .c o m*/
public static Long validateLong(Object bean, Field field, Locale locale) {
    String value = ValidatorUtils.getValueAsString(bean, field.getProperty());

    return GenericTypeValidator.formatLong(value, locale);
}

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

/**
 * Checks if the field can safely be converted to a long primitive.
 *
 * @param bean      The bean validation is being performed on.
 * @param va        The <code>ValidatorAction</code> that is currently
 *                  being performed.//  w  w w.  j  a  v a2  s .  co  m
 * @param field     The <code>Field</code> object associated with the
 *                  current field being validated.
 * @param errors    The <code>ActionMessages</code> object to add errors
 *                  to if any validation errors occur.
 * @param validator The <code>Validator</code> instance, used to access
 *                  other field values.
 * @param request   Current request object.
 * @return true if valid, false otherwise.
 */
public static Object validateLongLocale(Object bean, ValidatorAction va, Field field, ActionMessages errors,
        Validator validator, HttpServletRequest request) {
    Object result = null;
    String value = null;

    value = evaluateBean(bean, field);

    if (GenericValidator.isBlankOrNull(value)) {
        return Boolean.TRUE;
    }

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

    result = GenericTypeValidator.formatLong(value, locale);

    if (result == null) {
        errors.add(field.getKey(), Resources.getActionMessage(validator, request, va, field));
    }

    return (result == null) ? Boolean.FALSE : result;
}