List of usage examples for org.apache.commons.validator Field getProperty
public String getProperty()
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.j a v a 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 ww w .j av a 2 s . 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 *//*from w w w .j a v a 2 s .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: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 w w . ja 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: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 w w w . j a v a 2 s . co m 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.ValidateIntegerArray.java
public static boolean validate(Object bean, ValidatorAction va, Field field, ActionMessages errors, HttpServletRequest request, ServletContext application) { try {/*from w w w . j av a2 s. c om*/ DynaActionForm form = (DynaActionForm) bean; String sProperty = field.getProperty(); String[] integerArray = (String[]) form.get(sProperty); if ((integerArray == null) || (integerArray.length <= 0)) { errors.add(field.getKey(), Resources.getActionMessage(request, va, field)); return true; } for (int i = 0; i < integerArray.length; i++) { if (integerArray[i].equals("") || !StringUtils.isNumeric(integerArray[i])) { errors.add(field.getKey(), Resources.getActionMessage(request, va, field)); return true; } } return false; } catch (Exception e) { errors.add(field.getKey(), Resources.getActionMessage(request, va, field)); 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 a 2 s. com*/ 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; }/* ww w. ja v a 2s. co 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.ValidateMultiRadioSelect.java
/** * Verifies if the hashmap, that contains the unique multi-radio button * select, is not empty and has no empty fields Which means that by default * all key entries must exist and be empty * //ww w .j a v a 2 s . c om * @param bean * @param va * @param field * @param errors * @param request * @return */ public static boolean validate(Object bean, ValidatorAction va, Field field, ActionMessages errors, HttpServletRequest request, ServletContext application) { DynaActionForm form = (DynaActionForm) bean; HashMap hashMap = (HashMap) form.get(field.getProperty()); if (hashMap.keySet().size() == 0) { errors.add(field.getKey(), Resources.getActionMessage(request, va, field)); return false; } Iterator iterator = hashMap.keySet().iterator(); while (iterator.hasNext()) { String key = (String) iterator.next(); if (hashMap.get(key).equals("")) { errors.add(field.getKey(), Resources.getActionMessage(request, va, field)); return false; } } return true; }
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 w w w . j ava 2 s. c o m 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; } }