org.apache.commons.validator.Field.getVarValue()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(10.2k)|赞(0)|评价(0)|浏览(144)

本文整理了Java中org.apache.commons.validator.Field.getVarValue()方法的一些代码示例,展示了Field.getVarValue()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Field.getVarValue()方法的具体详情如下:
包路径:org.apache.commons.validator.Field
类名称:Field
方法名:getVarValue

Field.getVarValue介绍

[英]Retrieve a variable's value.
[中]检索变量的值。

代码示例

代码示例来源:origin: commons-validator/commons-validator

/**
  * Checks if the field can be successfully converted to a <code>date</code>.
  *
  * @param bean The value validation is being performed on.
  * @param field the field to use
  * @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 Date validateDate(Object bean, Field field) {
   String value = ValidatorUtils.getValueAsString(bean, field.getProperty());
   String datePattern = field.getVarValue("datePattern");
   String datePatternStrict = field.getVarValue("datePatternStrict");
   
   Date result = null;
   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);
    } 

   return result;
  }
}

代码示例来源:origin: commons-validator/commons-validator

if (!GenericValidator.isBlankOrNull(field.getVarValue("fieldJoin"))) {
  fieldJoin = field.getVarValue("fieldJoin");
while (!GenericValidator.isBlankOrNull(field.getVarValue("field[" + i + "]"))) {
  String dependProp = field.getVarValue("field[" + i + "]");
  String dependTest = field.getVarValue("fieldTest[" + i + "]");
  String dependTestValue = field.getVarValue("fieldValue[" + i + "]");
  String dependIndexed = field.getVarValue("fieldIndexed[" + i + "]");
  if (dependIndexed == null) {
    dependIndexed = "false";

代码示例来源:origin: commons-validator/commons-validator

private void checkForm(Locale locale, String formKey, String expectedVarValue) {
  // Retrieve the Form
  Form testForm = resources.getForm(locale, formKey);
  assertNotNull("Form '" +formKey+"' null for locale " + locale, testForm);
  // Validate the expected Form is retrieved by checking the "localeVar"
  // value of the field.
  Field testField = testForm.getField("testProperty");
  assertEquals("Incorrect Form '"   + formKey  + "' for locale '" + locale + "'",
         expectedVarValue, 
         testField.getVarValue("localeVar"));
}

代码示例来源:origin: commons-validator/commons-validator

assertEquals("testProperty1 - const 1", "testConstValue1", field1.getVarValue("var11"));
assertEquals("testProperty1 - const 2", "testConstValue2", field1.getVarValue("var12"));
assertEquals("testProperty2 - const 1", "testConstValue1", field2.getVarValue("var21"));
assertEquals("testProperty2 - const 2", "testConstValue2", field2.getVarValue("var22"));
assertEquals("testProperty1_fr - const 1", "testConstValue1_fr", field1_fr.getVarValue("var11_fr"));
assertEquals("testProperty1_fr - const 2", "testConstValue2_fr", field1_fr.getVarValue("var12_fr"));
assertEquals("testProperty2_fr - const 1", "testConstValue1_fr", field2_fr.getVarValue("var21_fr"));
assertEquals("testProperty2_fr - const 2", "testConstValue2_fr", field2_fr.getVarValue("var22_fr"));

代码示例来源:origin: org.openmobster.core/common

/**
  * 
  * @param bean
  * @param field
  * @return
  */
 public static boolean minimumLength(Object bean, Field field) 
 {
   String value = ValidatorUtils.getValueAsString(bean, field.getProperty());
   String varValue = field.getVarValue("minimumLength");
   return GenericValidator.minLength(value, Integer.parseInt(varValue));
 }    
}

代码示例来源:origin: org.springmodules/spring-modules-validation

try {
  int intValue = Integer.parseInt(value);
  int min = Integer.parseInt(field.getVarValue("min"));
  int max = Integer.parseInt(field.getVarValue("max"));

代码示例来源:origin: org.andromda.cartridges/andromda-jsf-cartridge-components

Field field)
final String mask = field.getVarValue("mask");
final String value = ObjectUtils.toString(object);
if (StringUtils.isNotBlank(value) && !GenericValidator.matchRegexp(

代码示例来源:origin: org.seasar.sastruts/sa-struts

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);

代码示例来源:origin: FenixEdu/fenixedu-academic

String sProperty2 = ValidatorUtils.getValueAsString(bean, field.getVarValue("month"));
String sProperty3 = ValidatorUtils.getValueAsString(bean, field.getVarValue("day"));

代码示例来源:origin: org.seasar.struts/s2-struts

private static org.seasar.struts.validator.Validator getValidator(Object bean, Field field) {
  String componentKey = field.getVarValue("componentKey");
  S2Container container = SingletonS2ContainerFactory.getContainer();
  try {
    return (org.seasar.struts.validator.Validator) container.getComponent(componentKey);
  } catch (ComponentNotFoundRuntimeException e) {
    return (org.seasar.struts.validator.Validator) container.getComponent(ClassUtil.forName(componentKey));
  }
}

代码示例来源:origin: org.springmodules/spring-modules-validation

String mask = field.getVarValue("mask");
String value = FieldChecks.extractValue(bean, field);
try {

代码示例来源:origin: FenixEdu/fenixedu-academic

String sProperty2 = ValidatorUtils.getValueAsString(bean, field.getVarValue("month"));
String sProperty3 = ValidatorUtils.getValueAsString(bean, field.getVarValue("day"));

代码示例来源:origin: FenixEdu/fenixedu-academic

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;
}

代码示例来源:origin: FenixEdu/fenixedu-academic

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;
}

代码示例来源:origin: org.springmodules/spring-modules-validation

int max = Integer.parseInt(field.getVarValue("maxlength"));

代码示例来源:origin: org.springmodules/spring-modules-validation

int min = Integer.parseInt(field.getVarValue("minlength"));

代码示例来源:origin: FenixEdu/fenixedu-academic

HttpServletRequest request, Comparator comparator) {
String greaterInputString = ValidatorUtils.getValueAsString(bean, field.getProperty());
String secondProperty = field.getVarValue("secondProperty");
String lowerInputString = ValidatorUtils.getValueAsString(bean, secondProperty);

代码示例来源:origin: FenixEdu/fenixedu-academic

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;
}

代码示例来源:origin: FenixEdu/fenixedu-academic

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;
  }
}

代码示例来源:origin: FenixEdu/fenixedu-academic

public static boolean validate(Object bean, ValidatorAction va, Field field, ActionMessages errors,
      HttpServletRequest request, ServletContext application) {

    try {

      DynaActionForm form = (DynaActionForm) bean;

      String sProperty = field.getProperty();
      Object[] multiBox = (Object[]) form.get(sProperty);

      String feminin = field.getVarValue("femininProperty");
      if ((multiBox != null) && (multiBox.length > 0)) {
        return true;
      }
      if (feminin != null && feminin.equalsIgnoreCase("true")) {
        errors.add(field.getKey(), new ActionError("errors.required.a.checkbox", field.getArg(0).getKey()));
      } else {
        errors.add(field.getKey(), new ActionError("errors.required.checkbox", field.getArg(0).getKey()));
      }

      return false;

    } catch (Exception e) {
      errors.add(field.getKey(), new ActionError("errors.required.undefined.checkbox", field.getArg(0).getKey()));
      return false;
    }

  }
}

相关文章