本文整理汇总了Java中org.apache.commons.validator.Field.getVarValue方法的典型用法代码示例。如果您正苦于以下问题:Java Field.getVarValue方法的具体用法?Java Field.getVarValue怎么用?Java Field.getVarValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.validator.Field
的用法示例。
在下文中一共展示了Field.getVarValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validateTwoFields
import org.apache.commons.validator.Field; //导入方法依赖的package包/类
/**
* Validates that two fields match.
* @param bean
* @param va
* @param field
* @param errors
*/
public static boolean validateTwoFields(Object bean, ValidatorAction va,
Field field, Errors errors) {
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)) {
FieldChecks.rejectValue(errors, field, va);
return false;
}
} catch (Exception e) {
FieldChecks.rejectValue(errors, field, va);
return false;
}
}
return true;
}
示例2: validateIdentico
import org.apache.commons.validator.Field; //导入方法依赖的package包/类
public static boolean validateIdentico(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;
}
示例3: validatePhone
import org.apache.commons.validator.Field; //导入方法依赖的package包/类
/**
* Validates a phone Number
* @param bean
* @param va
* @param field
* @param errors
* @param request
* @return
*/
public static boolean validatePhone(Object bean, ValidatorAction va,
Field field, ActionMessages errors, HttpServletRequest request) {
boolean isValid = false;
String dddField = field.getVarValue("firstProperty");
String ddd = ValidatorUtils.getValueAsString(bean, dddField).trim();
String phoneField = field.getVarValue("secondProperty");
String phone = ValidatorUtils.getValueAsString(bean, phoneField).trim();
try {
if (field.getKey().equals("phone")) {
if (ddd.length() != 2 || phone.length() != 8) {
errors.add(field.getKey(), Resources.getActionMessage(request, va, field));
isValid = false;
} else {
isValid = true;
}
}
} catch (Exception e) {
errors.add(field.getKey(), Resources.getActionMessage(request, va, field));
isValid = false;
}
return isValid;
}
示例4: validate
import org.apache.commons.validator.Field; //导入方法依赖的package包/类
/**
* Compares the two fields using the given comparator
*
* @param bean
* @param va
* @param field
* @param errors
* @param request
* @param comparator
* @return
*/
private static boolean validate(Object bean, ValidatorAction va, Field field, ActionMessages errors,
HttpServletRequest request, Comparator comparator) {
String greaterInputString = ValidatorUtils.getValueAsString(bean, field.getProperty());
String secondProperty = field.getVarValue("secondProperty");
String lowerInputString = ValidatorUtils.getValueAsString(bean, secondProperty);
if (!GenericValidator.isBlankOrNull(lowerInputString) && !GenericValidator.isBlankOrNull(greaterInputString)) {
try {
Double lowerInput = new Double(lowerInputString);
Double greaterInput = new Double(greaterInputString);
// if comparator result != VALUE then the condition is false
if (comparator.compare(lowerInput, greaterInput) != VALUE) {
errors.add(field.getKey(), Resources.getActionMessage(request, va, field));
return false;
}
return true;
} catch (NumberFormatException e) {
errors.add(field.getKey(), new ActionMessage(va.getMsg()));
return false;
}
}
return true;
}
示例5: validate
import org.apache.commons.validator.Field; //导入方法依赖的package包/类
public static boolean validate(Object bean, ValidatorAction va, Field field, ActionMessages errors,
HttpServletRequest request, ServletContext application) {
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(), new ActionMessage("errors.different.passwords"));
return false;
}
} catch (Exception e) {
errors.add(field.getKey(), new ActionMessage("errors.different.passwords"));
return false;
}
}
return true;
}
示例6: validate
import org.apache.commons.validator.Field; //导入方法依赖的package包/类
public static boolean validate(Object bean, ValidatorAction va, Field field, ActionMessages errors,
HttpServletRequest request, ServletContext application) {
try {
DynaActionForm form = (DynaActionForm) bean;
Boolean selectAllBox = (Boolean) form.get(field.getProperty());
String sProperty2 = field.getVarValue("secondProperty");
String[] multiBox = (String[]) form.get(sProperty2);
if (((selectAllBox != null) && selectAllBox.booleanValue()) || (multiBox != null) && (multiBox.length > 0)) {
return true;
}
errors.add(field.getKey(), new ActionMessage("errors.required.checkbox", field.getArg(0).getKey()));
return false;
} catch (Exception e) {
errors.add(field.getKey(), new ActionMessage("errors.required.checkbox", field.getArg(0).getKey()));
return false;
}
}
示例7: validateMaxByteLength
import org.apache.commons.validator.Field; //导入方法依赖的package包/类
/**
* バイト長が最大値より小さいかをチェックします。
*
* @param bean
* JavaBeans
* @param validatorAction
* バリデータアクション
* @param field
* フィールド定義
* @param errors
* エラーメッセージの入れ物
* @param validator
* バリデータ
* @param request
* リクエスト
* @return 検証結果がOKかどうか
*/
public static boolean validateMaxByteLength(Object bean,
ValidatorAction validatorAction, Field field,
ActionMessages errors, Validator validator,
HttpServletRequest request) {
String value = getValueAsString(bean, field);
if (!GenericValidator.isBlankOrNull(value)) {
try {
int max = Integer.parseInt(field.getVarValue("maxbytelength"));
String charset = field.getVarValue("charset");
if (!S2GenericValidator.maxByteLength(value, max, charset)) {
addError(errors, field, validator, validatorAction, request);
return false;
}
} catch (Exception e) {
addError(errors, field, validator, validatorAction, request);
return false;
}
}
return true;
}
示例8: validateMinByteLength
import org.apache.commons.validator.Field; //导入方法依赖的package包/类
/**
* バイト長が最小値より大きいかをチェックします。
*
* @param bean
* JavaBeans
* @param validatorAction
* バリデータアクション
* @param field
* フィールド定義
* @param errors
* エラーメッセージの入れ物
* @param validator
* バリデータ
* @param request
* リクエスト
* @return 検証結果がOKかどうか
*/
public static boolean validateMinByteLength(Object bean,
ValidatorAction validatorAction, Field field,
ActionMessages errors, Validator validator,
HttpServletRequest request) {
String value = getValueAsString(bean, field);
if (!GenericValidator.isBlankOrNull(value)) {
try {
int min = Integer.parseInt(field.getVarValue("minbytelength"));
String charset = field.getVarValue("charset");
if (!S2GenericValidator.minByteLength(value, min, charset)) {
addError(errors, field, validator, validatorAction, request);
return false;
}
} catch (Exception e) {
addError(errors, field, validator, validatorAction, request);
return false;
}
}
return true;
}
示例9: validateMask
import org.apache.commons.validator.Field; //导入方法依赖的package包/类
/**
* Checks if the field matches the regular expression in the field's mask attribute.
*
* @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.
* @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 field matches mask, false otherwise.
*/
public static boolean validateMask(Object bean,
ValidatorAction va, Field field,
ActionMessages errors,
Validator validator,
HttpServletRequest request) {
String mask = field.getVarValue("mask");
String value = null;
if (isString(bean)) {
value = (String) bean;
} else {
value = ValidatorUtils.getValueAsString(bean, field.getProperty());
}
try {
if (!GenericValidator.isBlankOrNull(value)
&& !GenericValidator.matchRegexp(value, mask)) {
errors.add(
field.getKey(),
Resources.getActionMessage(validator, request, va, field));
return false;
} else {
return true;
}
} catch (Exception e) {
log.error(e.getMessage(), e);
}
return true;
}
示例10: validateDate
import org.apache.commons.validator.Field; //导入方法依赖的package包/类
/**
* Checks if the field is a valid date. If the field has a datePattern variable,
* that will be used to format <code>java.text.SimpleDateFormat</code>. If the
* field has a datePatternStrict variable, that will be used to format <code>java.text.SimpleDateFormat</code>
* and the length will be checked so '2/12/1999' will not pass validation with
* the format 'MM/dd/yyyy' because the month isn't two digits. If no datePattern
* variable is specified, then the field gets the DateFormat.SHORT format for
* the locale. The setLenient method is set to <code>false</code> for all variations.
*
* @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.
* @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 validateDate(Object bean,
ValidatorAction va, Field field,
ActionMessages errors,
Validator validator,
HttpServletRequest request) {
Object result = null;
String value = null;
if (isString(bean)) {
value = (String) bean;
} else {
value = ValidatorUtils.getValueAsString(bean, field.getProperty());
}
String datePattern = field.getVarValue("datePattern");
String datePatternStrict = field.getVarValue("datePatternStrict");
Locale locale = RequestUtils.getUserLocale(request, null);
if (GenericValidator.isBlankOrNull(value)) {
return Boolean.TRUE;
}
try {
if (datePattern != null && datePattern.length() > 0) {
result = GenericTypeValidator.formatDate(value, datePattern, false);
} else if (datePatternStrict != null && datePatternStrict.length() > 0) {
result = GenericTypeValidator.formatDate(value, datePatternStrict, true);
} else {
result = GenericTypeValidator.formatDate(value, locale);
}
} catch (Exception e) {
log.error(e.getMessage(), e);
}
if (result == null) {
errors.add(field.getKey(), Resources.getActionMessage(validator, request, va, field));
}
return result == null ? Boolean.FALSE : result;
}
示例11: validateDate
import org.apache.commons.validator.Field; //导入方法依赖的package包/类
/**
* Checks if the field can be successfully converted to a <code>date</code>.
*
* @param value The value validation is being performed on.
* @return boolean If the field can be successfully converted
* to a <code>date</code> <code>true</code> is returned.
* Otherwise <code>false</code>.
*/
public static boolean validateDate(Object bean, Field field) {
String value = ValidatorUtils.getValueAsString(bean, field.getProperty());
String datePattern = field.getVarValue("datePattern");
boolean result = false;
if (datePattern != null && datePattern.length() > 0) {
result = GenericValidator.isDate(value, datePattern, false);
}
return result;
}
示例12: validateDateOrBlank
import org.apache.commons.validator.Field; //导入方法依赖的package包/类
public static boolean validateDateOrBlank(Object bean, Field field) {
String value = ValidatorUtils.getValueAsString(bean, field.getProperty());
String datePattern = field.getVarValue("datePattern");
boolean result = false;
if (datePattern != null && datePattern.length() > 0) {
result = GenericValidator.isDate(value, datePattern, false);
}
return GenericValidator.isBlankOrNull(value) || result;
}
示例13: validateDate
import org.apache.commons.validator.Field; //导入方法依赖的package包/类
/**
* Validates a date
*
* @param bean
* @param va
* @param field
* @param errors
* @param request
* @return
*/
public static boolean validateDate(Object bean, ValidatorAction va,
Field field, ActionMessages errors, HttpServletRequest request) {
String day = ValidatorUtils.getValueAsString(bean, field.getProperty());
String monthField = field.getVarValue("secondProperty");
String yearField = field.getVarValue("thirdProperty");
String month = ValidatorUtils.getValueAsString(bean, monthField);
String year = ValidatorUtils.getValueAsString(bean, yearField);
boolean isValid = true;
if(!GenericValidator.isBlankOrNull(day) || !GenericValidator.isBlankOrNull(month) || !GenericValidator.isBlankOrNull(year)){
try {
SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
formatter.setLenient( false );
Date date = (Date)formatter.parse(day+"/"+month+"/"+year);
} catch (Exception e) {
errors.add(field.getKey(), Resources.getActionMessage(request, va,field));
return false;
}
}
return isValid;
}
示例14: validateFloat
import org.apache.commons.validator.Field; //导入方法依赖的package包/类
public static boolean validateFloat(Object bean, ValidatorAction va, Field field, ActionMessages errors,
HttpServletRequest request, ServletContext application) {
String inputString = ValidatorUtils.getValueAsString(bean, field.getProperty());
String lowerValueString = field.getVarValue("value");
if ((inputString == null) || (inputString.length() == 0)) {
return true;
}
Double input = null;
Double lowerValue = null;
try {
input = new Double(inputString);
lowerValue = new Double(lowerValueString);
} catch (NumberFormatException e) {
errors.add(field.getKey(), Resources.getActionMessage(request, va, field));
return false;
}
if (!GenericValidator.isBlankOrNull(inputString)) {
if (input.floatValue() <= lowerValue.floatValue()) {
errors.add(field.getKey(), Resources.getActionMessage(request, va, field));
}
return false;
}
return true;
}
示例15: validateFloat0
import org.apache.commons.validator.Field; //导入方法依赖的package包/类
public static boolean validateFloat0(Object bean, ValidatorAction va, Field field, ActionMessages errors,
HttpServletRequest request, ServletContext application) {
String inputString = ValidatorUtils.getValueAsString(bean, field.getProperty());
String lowerValueString = field.getVarValue("value");
if ((inputString == null) || (inputString.length() == 0)) {
return true;
}
Double input = null;
Double lowerValue = null;
try {
input = new Double(inputString);
lowerValue = new Double(lowerValueString);
} catch (NumberFormatException e) {
errors.add(field.getKey(), Resources.getActionMessage(request, va, field));
return false;
}
if (!GenericValidator.isBlankOrNull(inputString)) {
if (input.floatValue() < lowerValue.floatValue()) {
errors.add(field.getKey(), Resources.getActionMessage(request, va, field));
}
return false;
}
return true;
}