List of usage examples for org.apache.commons.validator.util ValidatorUtils getValueAsString
public static String getValueAsString(Object bean, String property)
String
. From source file:net.sourceforge.fenixedu.presentationTier.validator.form.ValidateTwoFields.java
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 {// w w w .j a va 2 s. co m 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; }
From source file:net.sourceforge.fenixedu.presentationTier.validator.form.GreaterThen.java
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; }/*from w w w.j a v a2 s. c o m*/ 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; }
From source file:net.sourceforge.fenixedu.presentationTier.validator.form.ValidateDate.java
public static boolean validate(Object bean, ValidatorAction va, Field field, ActionMessages errors, HttpServletRequest request, ServletContext application) { String valueString = ValidatorUtils.getValueAsString(bean, field.getProperty()); String sProperty2 = ValidatorUtils.getValueAsString(bean, field.getVarValue("month")); String sProperty3 = ValidatorUtils.getValueAsString(bean, field.getVarValue("day")); if (((valueString == null) && (sProperty2 == null) && (sProperty3 == null)) || ((valueString.length() == 0) && (sProperty2.length() == 0) && (sProperty3.length() == 0))) { // errors.add(field.getKey(),Resources.getActionError(request, va, // field)); return true; }/*from w ww. ja va2s . c o m*/ Integer year = null; Integer month = null; Integer day = null; try { year = new Integer(valueString); month = new Integer(sProperty2); day = new Integer(sProperty3); } catch (NumberFormatException e) { errors.add(field.getKey(), Resources.getActionMessage(request, va, field)); return false; } if (!GenericValidator.isBlankOrNull(valueString)) { if (!Data.validDate(day, month, year) || year == null || month == null || day == null || year.intValue() < 1 || month.intValue() < 0 || day.intValue() < 1) { errors.add(field.getKey(), Resources.getActionMessage(request, va, field)); } return false; } return true; }
From source file:com.sapienter.jbilling.server.user.validator.AlphaNumValidator.java
public static boolean validateAlphaNum(Object bean, ValidatorAction va, Field field, ActionErrors errors, HttpServletRequest request, ServletContext application) { String value = ValidatorUtils.getValueAsString(bean, field.getProperty()); if (!GenericValidator.isBlankOrNull(value)) { try {/*from www .j a v a 2 s .c om*/ if (!basicValidation(value)) { errors.add(field.getKey(), Resources.getActionError(request, va, field)); return false; } } catch (Exception e) { errors.add(field.getKey(), Resources.getActionError(request, va, field)); return false; } } return true; }
From source file:net.sourceforge.fenixedu.presentationTier.validator.form.ValidateCompareTwoFields.java
/** * Compares the two fields using the given comparator * //from w ww . j av a 2 s . co m * @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; }
From source file:com.myproject.validator.CustomValidator.java
/** * Example validator for comparing the equality of two fields * * http://struts.apache.org/userGuide/dev_validator.html * http://www.raibledesigns.com/page/rd/20030226 *//*from w ww .j a va 2s . c o m*/ public static boolean validateTwoFields(Object bean, ValidatorAction va, Field field, ActionMessages errors, HttpServletRequest request) { String value = ValidatorUtils.getValueAsString(bean, field.getProperty()); String property2 = field.getVarValue("secondProperty"); String value2 = ValidatorUtils.getValueAsString(bean, property2); 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:com.core.validators.CommonValidator.java
/** * Throws a runtime exception if the value of the argument is "RUNTIME", * an exception if the value of the argument is "CHECKED", and a * ValidatorException otherwise.//from ww w . j ava 2 s .com * * @throws RuntimeException with "RUNTIME-EXCEPTION as message" * if value is "RUNTIME" * @throws Exception with "CHECKED-EXCEPTION" as message * if value is "CHECKED" * @throws ValidatorException with "VALIDATOR-EXCEPTION" as message * otherwise */ public static boolean validateRaiseException(final Object bean, final Field field) throws Exception { final String value = ValidatorUtils.getValueAsString(bean, field.getProperty()); if ("RUNTIME".equals(value)) { throw new RuntimeException("RUNTIME-EXCEPTION"); } else if ("CHECKED".equals(value)) { throw new Exception("CHECKED-EXCEPTION"); } else { throw new ValidatorException("VALIDATOR-EXCEPTION"); } }
From source file:alpha.portal.webapp.util.ValidationUtil.java
/** * Validates that two fields match.//from w w w . jav a 2s . c o m * * @param bean * the bean * @param va * the va * @param field * the field * @param errors * the errors * @return true, if successful */ public static boolean validateTwoFields(final Object bean, final ValidatorAction va, final Field field, final Errors errors) { final String value = ValidatorUtils.getValueAsString(bean, field.getProperty()); final String sProperty2 = field.getVarValue("secondProperty"); final String value2 = ValidatorUtils.getValueAsString(bean, sProperty2); if (!GenericValidator.isBlankOrNull(value)) { try { if (!value.equals(value2)) { FieldChecks.rejectValue(errors, field, va); return false; } } catch (final Exception e) { FieldChecks.rejectValue(errors, field, va); return false; } } return true; }
From source file:com.panet.imeta.job.entry.validator.NotBlankValidator.java
public boolean validate(CheckResultSourceInterface source, String propertyName, List<CheckResultInterface> remarks, ValidatorContext context) { String value = ValidatorUtils.getValueAsString(source, propertyName); if (GenericValidator.isBlankOrNull(value)) { JobEntryValidatorUtils.addFailureRemark(source, propertyName, VALIDATOR_NAME, remarks, JobEntryValidatorUtils.getLevelOnFail(context, VALIDATOR_NAME)); return false; } else {/*from w w w . j av a 2s. c o m*/ return true; } }
From source file:net.sourceforge.fenixedu.presentationTier.validator.form.GreaterThen.java
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; }/*from w ww.j av a 2 s . c o m*/ 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; }