List of usage examples for org.apache.commons.validator Field getVarValue
public String getVarValue(String mainKey)
From source file:jamm.webapp.JammValidators.java
/** * Checks if a field is identical to a second field. Useful for * cases where you are comparing passwords. Based on work in the * <i>Struts in Action</i> published by Manning. * * @param bean The bean validation is being performed on. * @param va The ValidatorAction that is currently being performed. * @param field The Field object associated with the current field * being validated./* w ww .ja va 2s . c o m*/ * @param errors The ActionErrors object to add errors to if any * validation errors occur. * @param request Current request object. * @return True if valid or field blank, false otherwise. */ public static boolean validateIdentical(Object bean, ValidatorAction va, Field field, ActionErrors errors, HttpServletRequest request) { String value = ValidatorUtil.getValueAsString(bean, field.getProperty()); String sProperty2 = field.getVarValue("secondProperty"); String value2 = ValidatorUtil.getValueAsString(bean, sProperty2); if (!GenericValidator.isBlankOrNull(value)) { if (!value.equals(value2)) { errors.add(field.getKey(), Resources.getActionError(request, va, field)); return false; } } return true; }
From source file:alpha.portal.webapp.util.ValidationUtil.java
/** * Validates that two fields match./*from w ww . j a v a2s . 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.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 *//*w ww . jav a 2s .co 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: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 {//from w ww . j a va2 s.com 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 .ja va2 s . c om 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.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; }// w ww. j a v a2s. 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.ValidateMultiBoxWithSelectAllCheckBox.java
public static boolean validate(Object bean, ValidatorAction va, Field field, ActionMessages errors, HttpServletRequest request, ServletContext application) { try {// w w w . j a v a 2 s. com 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; } }
From source file:net.sourceforge.fenixedu.presentationTier.validator.form.ValidateMultiBox.java
public static boolean validate(Object bean, ValidatorAction va, Field field, ActionMessages errors, HttpServletRequest request, ServletContext application) { try {/*from ww w. ja v a2 s . c om*/ 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; } }
From source file:net.sourceforge.fenixedu.presentationTier.validator.form.ValidateDate.java
public static boolean threeArgsDate(Object bean, ValidatorAction va, Field field, ActionMessages errors, HttpServletRequest request, ServletContext application) { String valueString1 = ValidatorUtils.getValueAsString(bean, field.getProperty()); String sProperty2 = ValidatorUtils.getValueAsString(bean, field.getVarValue("month")); String sProperty3 = ValidatorUtils.getValueAsString(bean, field.getVarValue("day")); if (((valueString1 == null) && (sProperty2 == null) && (sProperty3 == null)) || ((valueString1.length() == 0) && (sProperty2.length() == 0) && (sProperty3.length() == 0))) { // errors.add(field.getKey(),Resources.getActionError(request, va, // field)); return true; }//w w w . j a v a 2 s. c o m Integer year = null; Integer month = null; Integer day = null; try { year = new Integer(valueString1); month = new Integer(sProperty2); day = new Integer(sProperty3); } catch (NumberFormatException e) { errors.add(field.getKey(), Resources.getActionMessage(request, va, field)); return false; } String date = new String(day.toString() + "/" + month.toString() + "/" + year); String datePattern = "dd/MM/yyyy"; if (!GenericValidator.isDate(date, datePattern, false)) { 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; }// w w w . j av a2s . c om 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; }