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

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

Introduction

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

Prototype

public static Byte formatByte(String value) 

Source Link

Document

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

Usage

From source file:jp.terasoluna.fw.validation.FieldChecks.java

/**
 * ?byte?????//from   w  w  w.j  ava  2s . co  m
 *
 * @param bean ?JavaBean
 * @param va ?<code>ValidatorAction</code>
 * @param field ?<code>Field</code>
 * @param errors ?????
 * ??
 * @return ??????<code>true</code>?
 * ????<code>false</code>?
 */
public boolean validateByte(Object bean, ValidatorAction va, Field field, ValidationErrors errors) {
    // 
    String value = extractValue(bean, field);
    if (StringUtils.isEmpty(value)) {
        return true;
    }

    // 
    if (GenericTypeValidator.formatByte(value) == null) {
        rejectValue(errors, field, va, bean);
        return false;
    }
    return true;
}

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

/**
 * Checks if the field can safely be converted to a byte primitive.
 *
 * @param bean      The bean validation is being performed on.
 * @param va        The <code>ValidatorAction</code> that is currently
 *                  being performed./*w w  w  .  ja va 2s .com*/
 * @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 validateByte(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;
    }

    result = GenericTypeValidator.formatByte(value);

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

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

From source file:org.megatome.frame2.validator.CommonsFieldValidator.java

/**
 * Validate that a value can be converted to a byte value.
 * /*from   w  w w  .j av  a  2s  .com*/
 * @param value
 *            The value to validate
 * @param va
 *            The validator action
 * @param errors
 *            Errors object to populate
 * @param field
 *            The field to validate
 * @return The Byte value of the field, or null if it could not be
 *         converted.
 */
public static Byte validateByte(String value, ValidatorAction va, Errors errors, Field field) {
    if (value == null) {
        return null;
    }
    Byte result = null;
    result = GenericTypeValidator.formatByte(value);
    if (result == null) {
        addError(va, errors, field);
    }
    return result;
}

From source file:org.springmodules.commons.validator.FieldChecks.java

/**
 * Checks if the field can safely be converted to a byte primitive.
 *
 * @param bean The bean validation is being performed on.
 * @param va The <code>ValidatorAction</code> that is currently being
 * performed./*  w w w .  ja v  a2 s .c o  m*/
 * @param field The <code>Field</code> object associated with the current
 * field being validated.
 * @param errors The <code>Errors</code> object to add errors to if any
 * validation errors occur.
 * -param request
 * Current request object.
 * @return A Byte if valid, null otherwise.
 */
public static Byte validateByte(Object bean, ValidatorAction va, Field field, Errors errors) {

    Byte result = null;
    String value = extractValue(bean, field);

    if (!GenericValidator.isBlankOrNull(value)) {
        result = GenericTypeValidator.formatByte(value);
        if (result == null) {
            rejectValue(errors, field, va);
        }
    }
    return result;
}

From source file:org.springmodules.validation.commons.FieldChecks.java

/**
 * Checks if the field can safely be converted to a byte primitive.
 *
 * @param bean The bean validation is being performed on.
 * @param va The <code>ValidatorAction</code> that is currently being
 * performed.//from  w w  w. j a  va  2 s .  c o  m
 * @param field The <code>Field</code> object associated with the current
 * field being validated.
 * @param errors The <code>Errors</code> object to add errors to if any
 * validation errors occur.
 * -param request
 * Current request object.
 * @return A Byte if valid, null otherwise.
 */
public static Byte validateByte(Object bean, ValidatorAction va, Field field, Errors errors) {

    Byte result = null;
    String value = FieldChecks.extractValue(bean, field);

    if (!GenericValidator.isBlankOrNull(value)) {
        result = GenericTypeValidator.formatByte(value);
        if (result == null) {
            FieldChecks.rejectValue(errors, field, va);
        }
    }
    return result;
}

From source file:test.valid.TestTypeValidator.java

/**
 * Checks if the field can be successfully converted to a <code>byte</code>.
 *
 * @param value The value validation is being performed on.
 * @return boolean If the field can be successfully converted 
 * to a <code>byte</code> <code>true</code> is returned.  
 * Otherwise <code>false</code>.
 *//* ww  w.j  a va2s  .  c o m*/
public static Byte validateByte(Object bean, Field field) {
    String value = ValidatorUtils.getValueAsString(bean, field.getProperty());

    return GenericTypeValidator.formatByte(value);
}