/** * Add a <code>Field</code> to the <code>Form</code>. * * @param f The field */ public void addField(Field f) { this.lFields.add(f); getFieldMap().put(f.getKey(), f); }
/** * Add a the result of a validator action. * * @param field The field validated. * @param validatorName The name of the validator. * @param result The result of the validation. * @param value The value returned by the validator. */ public void add( Field field, String validatorName, boolean result, Object value) { ValidatorResult validatorResult = this.getValidatorResult(field.getKey()); if (validatorResult == null) { validatorResult = new ValidatorResult(field); this.hResults.put(field.getKey(), validatorResult); } validatorResult.add(validatorName, result, value); }
/** * Returns an indexed property from the object we're validating. * * @param bean The bean to extract the indexed values from. * @throws ValidatorException If there's an error looking up the property * or, the property found is not indexed. */ Object[] getIndexedProperty(Object bean) throws ValidatorException { Object indexedProperty = null; try { indexedProperty = PropertyUtils.getProperty(bean, this.getIndexedListProperty()); } catch(IllegalAccessException e) { throw new ValidatorException(e.getMessage()); } catch(InvocationTargetException e) { throw new ValidatorException(e.getMessage()); } catch(NoSuchMethodException e) { throw new ValidatorException(e.getMessage()); } if (indexedProperty instanceof Collection) { return ((Collection<?>) indexedProperty).toArray(); } else if (indexedProperty.getClass().isArray()) { return (Object[]) indexedProperty; } else { throw new ValidatorException(this.getKey() + " is not indexed"); } } /**
/** * Returns the size of an indexed property from the object we're validating. * * @param bean The bean to extract the indexed values from. * @throws ValidatorException If there's an error looking up the property * or, the property found is not indexed. */ private int getIndexedPropertySize(Object bean) throws ValidatorException { Object indexedProperty = null; try { indexedProperty = PropertyUtils.getProperty(bean, this.getIndexedListProperty()); } catch(IllegalAccessException e) { throw new ValidatorException(e.getMessage()); } catch(InvocationTargetException e) { throw new ValidatorException(e.getMessage()); } catch(NoSuchMethodException e) { throw new ValidatorException(e.getMessage()); } if (indexedProperty == null) { return 0; } else if (indexedProperty instanceof Collection) { return ((Collection<?>)indexedProperty).size(); } else if (indexedProperty.getClass().isArray()) { return ((Object[])indexedProperty).length; } else { throw new ValidatorException(this.getKey() + " is not indexed"); } }
Field defaultField = dependsIt.next(); if (defaultField != null) { String fieldKey = defaultField.getKey(); if (!this.containsField(fieldKey)) { templFields.add(defaultField);
/** * Modifies the paramValue array with indexed fields. * * @param field * @param pos * @param paramValues */ private void handleIndexedField(Field field, int pos, Object[] paramValues) throws ValidatorException { int beanIndex = this.methodParameterList.indexOf(Validator.BEAN_PARAM); int fieldIndex = this.methodParameterList.indexOf(Validator.FIELD_PARAM); Object indexedList[] = field.getIndexedProperty(paramValues[beanIndex]); // Set current iteration object to the parameter array paramValues[beanIndex] = indexedList[pos]; // Set field clone with the key modified to represent // the current field Field indexedField = (Field) field.clone(); indexedField.setKey( ValidatorUtils.replace( indexedField.getKey(), Field.TOKEN_INDEXED, "[" + pos + "]")); paramValues[fieldIndex] = indexedField; }
assertTrue("firstName in " + FORM_KEY + " should be the first in the list", fieldFirstName.getKey().equals("firstName")); assertTrue("lastName in " + FORM_KEY + " should be the first in the list", fieldLastName.getKey().equals("lastName")); assertTrue("firstName in " + FORM_KEY2 + " should be the first in the list", fieldFirstName.getKey().equals("firstName")); assertTrue("lastName in " + FORM_KEY2 + " should be the first in the list", fieldLastName.getKey().equals("lastName"));
/** * Executes the given ValidatorAction and all ValidatorActions that it * depends on. * @return true if the validation succeeded. */ private boolean validateForRule( ValidatorAction va, ValidatorResults results, Map<String, ValidatorAction> actions, Map<String, Object> params, int pos) throws ValidatorException { ValidatorResult result = results.getValidatorResult(this.getKey()); if (result != null && result.containsAction(va.getName())) { return result.isValid(va.getName()); } if (!this.runDependentValidators(va, results, actions, params, pos)) { return false; } return va.executeValidationMethod(this, params, results, pos); }
boolean this_required = false; if (field.isIndexed() && dependIndexed.equalsIgnoreCase("true")) { String key = field.getKey(); if ((key.contains("[")) && (key.contains("]"))) { String ind = key.substring(0, key.indexOf(".") + 1);
/** * Add a <code>Field</code> to the <code>Form</code>. * * @param f The field */ public void addField(Field f) { this.lFields.add(f); this.hFields.put(f.getKey(), f); }
/** * Add a <code>Field</code> to the <code>Form</code>. * * @param f The field */ public void addField(Field f) { this.lFields.add(f); getFieldMap().put(f.getKey(), f); }
/** * Add a the result of a validator action. * * @param field The field validated. * @param validatorName The name of the validator. * @param result The result of the validation. * @param value The value returned by the validator. */ public void add( Field field, String validatorName, boolean result, Object value) { ValidatorResult validatorResult = this.getValidatorResult(field.getKey()); if (validatorResult == null) { validatorResult = new ValidatorResult(field); this.hResults.put(field.getKey(), validatorResult); } validatorResult.add(validatorName, result, value); }
private static void addError(ActionMessages errors, Field field, Validator validator, ValidatorAction validatorAction, HttpServletRequest request) { errors.add(field.getKey(), Resources.getActionMessage(validator, request, validatorAction, field)); } }
/** * Add a the result of a validator action. * * @param field The field validated. * @param validatorName The name of the validator. * @param result The result of the validation. * @param value The value returned by the validator. */ public void add( Field field, String validatorName, boolean result, Object value) { ValidatorResult validatorResult = this.getValidatorResult(field.getKey()); if (validatorResult == null) { validatorResult = new ValidatorResult(field); this.hResults.put(field.getKey(), validatorResult); } validatorResult.add(validatorName, result, value); }
/** * エラーメッセージを追加します。 * * @param errors * エラーメッセージの入れ物 * @param field * フィールド定義 * @param validator * バリデータ * @param validatorAction * バリデータアクション * @param request * リクエスト */ protected static void addError(ActionMessages errors, Field field, Validator validator, ValidatorAction validatorAction, HttpServletRequest request) { errors.add(field.getKey(), Resources.getActionMessage(validator, request, validatorAction, field)); } }
/** * Process a validation failure. */ private static void processFailure(ActionMessages errors, Field field, String validator, Throwable t) { // Log the error String logErrorMsg = sysmsgs.getMessage("validation.failed", validator, field.getProperty(), t.toString()); log.error(logErrorMsg); // Add general "system error" message to show to the user String userErrorMsg = sysmsgs.getMessage("system.error"); errors.add(field.getKey(), new ActionMessage(userErrorMsg, false)); }
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; }
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; } }
/** * Executes the given ValidatorAction and all ValidatorActions that it * depends on. * @return true if the validation succeeded. */ private boolean validateForRule( ValidatorAction va, ValidatorResults results, Map<String, ValidatorAction> actions, Map<String, Object> params, int pos) throws ValidatorException { ValidatorResult result = results.getValidatorResult(this.getKey()); if (result != null && result.containsAction(va.getName())) { return result.isValid(va.getName()); } if (!this.runDependentValidators(va, results, actions, params, pos)) { return false; } return va.executeValidationMethod(this, params, results, pos); }