List of usage examples for org.apache.commons.validator GenericTypeValidator formatInt
public static Integer formatInt(String value)
From source file:com.panet.imeta.job.entry.validator.IntegerValidator.java
public boolean validate(CheckResultSourceInterface source, String propertyName, List<CheckResultInterface> remarks, ValidatorContext context) { Object result = null;/*from ww w. java 2s . c o m*/ String value = null; value = getValueAsString(source, propertyName); if (GenericValidator.isBlankOrNull(value)) { return true; } result = GenericTypeValidator.formatInt(value); if (result == null) { addFailureRemark(source, propertyName, VALIDATOR_NAME, remarks, getLevelOnFail(context, VALIDATOR_NAME)); return false; } return true; }
From source file:com.core.validators.CommonValidator.java
/** * Checks if field is positive assuming it is an integer * //from w w w .java 2 s . c o m * @param value The value validation is being performed on. * @param field Description of the field to be evaluated * @return boolean If the integer field is greater than zero, returns * true, otherwise returns false. */ public static boolean validatePositive(Object bean, Field field) { String value = ValidatorUtils.getValueAsString(bean, field.getProperty()); return GenericTypeValidator.formatInt(value).intValue() > 0; }
From source file:jp.terasoluna.fw.validation.FieldChecks.java
/** * ?int?????//from w ww . j a va2 s . c o 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 validateInteger(Object bean, ValidatorAction va, Field field, ValidationErrors errors) { // String value = extractValue(bean, field); if (StringUtils.isEmpty(value)) { return true; } // if (GenericTypeValidator.formatInt(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 an int 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 v a2 s . c om * @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 validateInteger(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.formatInt(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 an integer value. * //from ww w. j a v a 2 s.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 Integer value of the field, or null if it could not be * converted. */ public static Integer validateInteger(String value, ValidatorAction va, Errors errors, Field field) { if (value == null) { return null; } Integer result = null; result = GenericTypeValidator.formatInt(value); if (result == null) { addError(va, errors, field); } return result; }
From source file:org.sgrp.singer.validator.ArrayFieldChecks.java
/** * Checks for each value of the field if it can safely be converted to an int primitive. * * @param bean The bean validation is being performed on. * @param va The <code>ValidatorAction</code> that is currently being performed. * @param field The <code>Field</code> object associated with the current * field being validated./*from w w w .ja v a 2 s . c om*/ * @param errors The <code>ActionMessages</code> object to add errors to if any * validation errors occur. * @param request Current request object. * @return true if valid, false otherwise. */ public static Object[] validateInteger(Object bean, ValidatorAction va, Field field, ActionMessages errors, HttpServletRequest request) { String[] value = null; if (isStringArray(bean)) { value = (String[]) bean; } else { value = new String[0]; } Object[] result = new Object[value.length]; for (int i = 0; i < value.length; i++) { if (GenericValidator.isBlankOrNull(value[i])) { result[i] = Boolean.TRUE; } else { result[i] = GenericTypeValidator.formatInt(value[i]); } if (result[i] == null) { errors.add(field.getKey(), Resources.getActionMessage(request, va, field)); result[i] = Boolean.FALSE; } } return result; }
From source file:org.springmodules.commons.validator.FieldChecks.java
/** * Checks if the field can safely be converted to an int 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 a 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 An Integer if valid, a null otherwise. */ public static Integer validateInteger(Object bean, ValidatorAction va, Field field, Errors errors) { Integer result = null; String value = extractValue(bean, field); if (!GenericValidator.isBlankOrNull(value)) { result = GenericTypeValidator.formatInt(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 an int 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 va2 s . co 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 An Integer if valid, a null otherwise. */ public static Integer validateInteger(Object bean, ValidatorAction va, Field field, Errors errors) { Integer result = null; String value = FieldChecks.extractValue(bean, field); if (!GenericValidator.isBlankOrNull(value)) { result = GenericTypeValidator.formatInt(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>int</code>. * * @param value The value validation is being performed on. * @return boolean If the field can be successfully converted * to a <code>int</code> <code>true</code> is returned. * Otherwise <code>false</code>. *///ww w .j ava2 s .c om public static Integer validateInt(Object bean, Field field) { String value = ValidatorUtils.getValueAsString(bean, field.getProperty()); return GenericTypeValidator.formatInt(value); }