/** * see AbstractValidator#onValidate(IValidatable) */ protected void onValidate(IValidatable validatable) { if (((String)validatable.getValue()).length() != length) { error(validatable); } }
/** * Gets a <code>String</code> exact length validator for checking if a string length is exactly * the same as the given length value. If that is not the case, then an error message will be * generated with the key "StringValidator.exact". The message keys that can be used are: * <p> * <ul> * <li>${exact}: the maximum length</li> * <li>${length}: the length of the user input</li> * <li>${input}: the input the user gave</li> * <li>${name}: the name of the <code>Component</code> that failed</li> * <li>${label}: the label of the <code>Component</code> - either comes from * <code>FormComponent.labelModel</code> or resource key [form-id].[form-component-id] in that * order</li> * </ul> * * @param length * the required length of the string * * @return the requested <code>StringValidator</code> */ public static StringValidator exactLength(int length) { return new ExactLengthValidator(length); }
/** * Gets a <code>String</code> exact length validator for checking if a string length is * exactly the same as the given length value. If that is not the case, then an error message * will be generated with the key "StringValidator.exact". The message keys that can be used * are: * <p> * <ul> * <li>${exact}: the maximum length</li> * <li>${length}: the length of the user input</li> * <li>${input}: the input the user gave</li> * <li>${name}: the name of the <code>Component</code> that failed</li> * <li>${label}: the label of the <code>Component</code> - either comes from * <code>FormComponent.labelModel</code> or resource key [form-id].[form-component-id] in that * order</li> * </ul> * * @param length * the required length of the string * * @return the requested <code>StringValidator</code> */ public static StringValidator exactLength(int length) { return new ExactLengthValidator(length); }
/** * @param component * @param length * @return */ public String exactLengthMessage(Component component, ExactLengthValidator exactLengthValidator) { int length = exactLengthValidator.getLength(); String minMessage = addToBuffer( component.getId(), "minlength|" + length, escapeJavaScriptString(formatExactLengthMessage(component, "StringValidator.exact", length))); String maxMessage = addToBuffer( component.getId(), "maxlength|" + length, escapeJavaScriptString(formatExactLengthMessage(component, "StringValidator.exact", length))); return minMessage + maxMessage; }
/** * @param component * @param length * @return */ public String exactLengthMessage(Component component, ExactLengthValidator exactLengthValidator) { int length = exactLengthValidator.getLength(); String minMessage = addToBuffer( component.getId(), "minlength|" + length, escapeJavaScriptString(formatExactLengthMessage(component, "StringValidator.exact", length))); String maxMessage = addToBuffer( component.getId(), "maxlength|" + length, escapeJavaScriptString(formatExactLengthMessage(component, "StringValidator.exact", length))); return minMessage + maxMessage; }
/** * see AbstractValidator#onValidate(IValidatable) */ @Override protected void onValidate(IValidatable<String> validatable) { if ((validatable.getValue()).length() != length) { error(validatable); } }