Example usage for org.apache.commons.validator.util ValidatorUtils getValueAsString

List of usage examples for org.apache.commons.validator.util ValidatorUtils getValueAsString

Introduction

In this page you can find the example usage for org.apache.commons.validator.util ValidatorUtils getValueAsString.

Prototype

public static String getValueAsString(Object bean, String property) 

Source Link

Document

Convenience method for getting a value from a bean property as a String.

Usage

From source file:org.jresearch.gossip.validator.Validator.java

/**
 * DOCUMENT ME!/*from  w w  w  . java 2  s.  co m*/
 * 
 * @param bean
 *            DOCUMENT ME!
 * @param va
 *            DOCUMENT ME!
 * @param field
 *            DOCUMENT ME!
 * @param errors
 *            DOCUMENT ME!
 * @param request
 *            DOCUMENT ME!
 * 
 * @return DOCUMENT ME!
 */
public boolean validateEmail(Object bean, ValidatorAction va, Field field, ActionMessages errors,
        HttpServletRequest request) {
    String value = ValidatorUtils.getValueAsString(bean, field.getProperty());
    Perl5Util util = new Perl5Util();

    if (!GenericValidator.isBlankOrNull(value)) {
        if ((!util.match("/( )|(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)|(^_+@)|(^\\-+@)/", value)) && util.match(
                "/^[\\w\\'\\.\\-]+@((\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)|[a-zA-Z0-9\\-]{2,})$/",
                value)) {
            return true;
        } else {

            errors.add(field.getKey(), Resources.getActionMessage(request, va, field));

            return false;
        }
    }

    return true;
}

From source file:org.jresearch.gossip.validator.Validator.java

/**
 * DOCUMENT ME!//  ww  w  .java 2 s. c o  m
 * 
 * @param bean
 *            DOCUMENT ME!
 * @param va
 *            DOCUMENT ME!
 * @param field
 *            DOCUMENT ME!
 * @param errors
 *            DOCUMENT ME!
 * @param request
 *            DOCUMENT ME!
 * 
 * @return DOCUMENT ME!
 */
public boolean validateTwoFields(Object bean, ValidatorAction va, Field field, ActionMessages errors,
        HttpServletRequest request) {
    String value = ValidatorUtils.getValueAsString(bean, field.getProperty());
    String sProperty2 = field.getVarValue("secondProperty");
    String value2 = ValidatorUtils.getValueAsString(bean, sProperty2);

    if (!GenericValidator.isBlankOrNull(value)) {
        try {
            if (!value.equals(value2)) {
                errors.add(field.getKey(), Resources.getActionMessage(request, va, field));

                return false;
            }
        } catch (Exception e) {
            errors.add(field.getKey(), Resources.getActionMessage(request, va, field));

            return false;
        }
    }

    return true;
}

From source file:org.jresearch.gossip.validator.Validator.java

public boolean validateConfirmCode(Object bean, ValidatorAction va, Field field, ActionMessages errors,
        HttpServletRequest request) {/*from ww  w.  j a v a  2s .c  om*/
    String value = ValidatorUtils.getValueAsString(bean, field.getProperty());
    HttpSession session = request.getSession();
    String value2 = (String) session.getAttribute(IConst.SESSION.CONFIRM_CODE);

    if (!GenericValidator.isBlankOrNull(value)) {
        try {
            if (!value.equals(value2)) {
                errors.add(field.getKey(), Resources.getActionMessage(request, va, field));

                return false;
            }
        } catch (Exception e) {
            errors.add(field.getKey(), Resources.getActionMessage(request, va, field));

            return false;
        }
    }

    return true;
}

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

/**
 * Validate an email address//  w  w w  .  ja  v  a 2  s.c  om
 * 
 * @param bean
 *            The event containing the field to validate.
 * @param va
 *            The validator action
 * @param errors
 *            Errors object to populate
 * @param field
 *            The field to validate.
 * @return True if the field passes validation.
 */
public static boolean validateEmail(Object bean, ValidatorAction va, Errors errors, Field field) {
    String value = ValidatorUtils.getValueAsString(bean, field.getProperty());
    return validateEmail(value, va, errors, field);
}

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

/**
 * Validate that a required value is present.
 * // w  w w. ja v  a  2s .  co  m
 * @param bean
 *            The event containing the field to validate.
 * @param va
 *            The validator action
 * @param errors
 *            Errors object to populate
 * @param field
 *            The field to validate
 * @return True if the field contains a value.
 */
public static boolean validateRequired(Object bean, ValidatorAction va, Errors errors, Field field) {
    String value = ValidatorUtils.getValueAsString(bean, field.getProperty());
    return validateRequired(value, va, errors, field);
}

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

/**
 * Validate that a value matches a regular expression value.
 * //from   ww  w  . j a v  a2 s . co m
 * @param bean
 *            The event containing the field to validate.
 * @param va
 *            The validator action
 * @param errors
 *            Errors object to populate
 * @param field
 *            The field to validate
 * @return True if the field matches the regular expression.
 */
public static boolean mask(Object bean, ValidatorAction va, Errors errors, Field field) {
    String value = ValidatorUtils.getValueAsString(bean, field.getProperty());
    return mask(value, va, errors, field);
}

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

/**
 * Validate that a value can be converted to a byte value.
 * /*  w  w w  .jav a  2  s.  com*/
 * @param bean
 *            The event containing the field 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(Object bean, ValidatorAction va, Errors errors, Field field) {
    String value = ValidatorUtils.getValueAsString(bean, field.getProperty());
    return validateByte(value, va, errors, field);
}

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

/**
 * Validate that a value can be converted to a short value.
 * /*  w w w. j a va2 s.  c o  m*/
 * @param bean
 *            The event containing the field to validate
 * @param va
 *            The validator action
 * @param errors
 *            Errors object to populate
 * @param field
 *            The field to validate
 * @return The Short value of the field, or null if it could not be
 *         converted.
 */
public static Short validateShort(Object bean, ValidatorAction va, Errors errors, Field field) {
    String value = ValidatorUtils.getValueAsString(bean, field.getProperty());
    return validateShort(value, va, errors, field);
}

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

/**
 * Validate that a value can be converted to an integer value.
 * /*from ww  w .j a va 2 s  .  c  om*/
 * @param bean
 *            The event containing the field to validate
 * @param va
 *            The validator action
 * @param errors
 *            Errors object to populate
 * @param field
 *            The field to validate
 * @return The Integer value of the field, or null if it could not be
 *         converted.
 */
public static Integer validateInteger(Object bean, ValidatorAction va, Errors errors, Field field) {
    String value = ValidatorUtils.getValueAsString(bean, field.getProperty());
    return validateInteger(value, va, errors, field);
}

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

/**
 * Validate that a value can be converted to a long value.
 * //w w w  . ja  v  a 2  s .c  o m
 * @param bean
 *            The event containing the field to validate
 * @param va
 *            The validator action
 * @param errors
 *            Errors object to populate
 * @param field
 *            The field to validate
 * @return The Long value of the field, or null if it could not be
 *         converted.
 */
public static Long validateLong(Object bean, ValidatorAction va, Errors errors, Field field) {
    String value = ValidatorUtils.getValueAsString(bean, field.getProperty());
    return validateLong(value, va, errors, field);
}