/** * see AbstractValidator#onValidate(IValidatable) */ protected void onValidate(IValidatable validatable) { final String value = (String)validatable.getValue(); if (value.length() < minimum || value.length() > maximum) { error(validatable); } }
/** * Gets a <code>String</code> range validator for checking if a string length falls between * the minimum and and maximum lengths. If that is not the case, then an error message will be * generated with the key "StringValidator.range". The message keys that can be used are: * <p> * <ul> * <li>${minimum}: the minimum length</li> * <li>${maximum}: 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 minimum * the minimum length of the string * @param maximum * the maximum length of the string * * @return the requested <code>StringValidator</code> */ public static StringValidator lengthBetween(int minimum, int maximum) { return new LengthBetweenValidator(minimum, maximum); }
/** * Gets a <code>String</code> range validator for checking if a string length falls between the * minimum and and maximum lengths. If that is not the case, then an error message will be * generated with the key "StringValidator.range". The message keys that can be used are: * <p> * <ul> * <li>${minimum}: the minimum length</li> * <li>${maximum}: 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 minimum * the minimum length of the string * @param maximum * the maximum length of the string * * @return the requested <code>StringValidator</code> */ public static StringValidator lengthBetween(int minimum, int maximum) { return new LengthBetweenValidator(minimum, maximum); }
/** * @param component * @param lengthBetweenValidator * @return */ public String lengthBetweenMessage(Component component, LengthBetweenValidator lengthBetweenValidator) { String minimum = String.valueOf(lengthBetweenValidator.getMinimum()); String maximum = String.valueOf(lengthBetweenValidator.getMaximum()); // Add a rule for a minlength with a Yav custom message // corresponding to the Wicket range message String minMessage = addToBuffer( component.getId(), "minlength|" + minimum, escapeJavaScriptString(formatRangeMessage(component, "NumberValidator.range", minimum, maximum))); // Add a rule for a maxlength with a Yav custom message // corresponding to the Wicket range message String maxMessage = addToBuffer( component.getId(), "maxlength|" + maximum, escapeJavaScriptString(formatRangeMessage(component, "NumberValidator.range", minimum, maximum))); return minMessage + maxMessage; }
/** * @param component * @param lengthBetweenValidator * @return */ public String lengthBetweenMessage(Component component, LengthBetweenValidator lengthBetweenValidator) { String minimum = String.valueOf(lengthBetweenValidator.getMinimum()); String maximum = String.valueOf(lengthBetweenValidator.getMaximum()); // Add a rule for a minlength with a Yav custom message // corresponding to the Wicket range message String minMessage = addToBuffer( component.getId(), "minlength|" + minimum, escapeJavaScriptString(formatRangeMessage(component, "NumberValidator.range", minimum, maximum))); // Add a rule for a maxlength with a Yav custom message // corresponding to the Wicket range message String maxMessage = addToBuffer( component.getId(), "maxlength|" + maximum, escapeJavaScriptString(formatRangeMessage(component, "NumberValidator.range", minimum, maximum))); return minMessage + maxMessage; }
/** * see AbstractValidator#onValidate(IValidatable) */ @Override protected void onValidate(IValidatable<String> validatable) { final String value = validatable.getValue(); if (value.length() < minimum || value.length() > maximum) { error(validatable); } }