Class StringValidator
- java.lang.Object
-
- org.apache.wicket.behavior.Behavior
-
- org.apache.wicket.validation.validator.AbstractRangeValidator<java.lang.Integer,java.lang.String>
-
- org.apache.wicket.validation.validator.StringValidator
-
- All Implemented Interfaces:
java.io.Serializable,IComponentAwareEventSink,IComponentAwareHeaderContributor,org.apache.wicket.util.io.IClusterable,IValidator<java.lang.String>
public class StringValidator extends AbstractRangeValidator<java.lang.Integer,java.lang.String>
Validator for checking if length of a string falls within [min,max] range. If either min or max arenullthey are not checked.If the component is attached to an
inputtag, amaxlenattribute will be added if the maximum is set. *Resource keys:
StringValidator.exactif min==max (exactLength(int))StringValidator.rangeif both min and max are notnullStringValidator.minimumif max isnull(minimumLength(int))StringValidator.maximumif min isnull(maximumLength(int))
Error Message Variables:
name: the id ofComponentthat failedlabel: the label of theComponent(either comes fromFormComponent.labelModelor resource key<form-id>.<form-component-id>input: the input valuelength: the length of the enteredminimum: the minimum allowed lengthmaximum: the maximum allowed length
- Author:
- igor
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.wicket.validation.validator.AbstractRangeValidator
AbstractRangeValidator.Mode
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedStringValidator()Constructor used for subclasses who want to set the range usingAbstractRangeValidator.setRange(Comparable, Comparable)StringValidator(java.lang.Integer minimum, java.lang.Integer maximum)Constructor that sets the minimum and maximum length values.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected IValidationErrordecorate(IValidationError error, IValidatable<java.lang.String> validatable)Allows subclasses to decorate reported errorsstatic StringValidatorexactLength(int length)protected java.lang.IntegergetValue(IValidatable<java.lang.String> validatable)Gets the value that should be validated against the rangeprotected booleanhasLengthAttribute(java.lang.String tagName)static StringValidatorlengthBetween(int minimum, int maximum)static StringValidatormaximumLength(int length)static StringValidatorminimumLength(int length)voidonComponentTag(Component component, ComponentTag tag)Called any time a component that has this behavior registered is rendering the component tag.-
Methods inherited from class org.apache.wicket.validation.validator.AbstractRangeValidator
getMaximum, getMinimum, getMode, setRange, validate
-
Methods inherited from class org.apache.wicket.behavior.Behavior
afterRender, beforeRender, bind, canCallListener, detach, getStatelessHint, isEnabled, isTemporary, onAttribute, onConfigure, onEvent, onException, onRemove, onTag, renderHead, unbind
-
-
-
-
Constructor Detail
-
StringValidator
public StringValidator(java.lang.Integer minimum, java.lang.Integer maximum)Constructor that sets the minimum and maximum length values.- Parameters:
minimum- the minimum lengthmaximum- the maximum length
-
StringValidator
protected StringValidator()
Constructor used for subclasses who want to set the range usingAbstractRangeValidator.setRange(Comparable, Comparable)
-
-
Method Detail
-
getValue
protected java.lang.Integer getValue(IValidatable<java.lang.String> validatable)
Description copied from class:AbstractRangeValidatorGets the value that should be validated against the range- Specified by:
getValuein classAbstractRangeValidator<java.lang.Integer,java.lang.String>- Returns:
- value to validate
-
decorate
protected IValidationError decorate(IValidationError error, IValidatable<java.lang.String> validatable)
Description copied from class:AbstractRangeValidatorAllows subclasses to decorate reported errors- Overrides:
decoratein classAbstractRangeValidator<java.lang.Integer,java.lang.String>- Returns:
- decorated error
-
onComponentTag
public void onComponentTag(Component component, ComponentTag tag)
Description copied from class:BehaviorCalled any time a component that has this behavior registered is rendering the component tag.- Overrides:
onComponentTagin classBehavior- Parameters:
component- the component that renders this tag currentlytag- the tag that is rendered
-
hasLengthAttribute
protected boolean hasLengthAttribute(java.lang.String tagName)
-
exactLength
public static StringValidator exactLength(int length)
- Parameters:
length-- Returns:
- a
StringValidatorthat generates an error if a string is not of an exact length
-
maximumLength
public static StringValidator maximumLength(int length)
- Parameters:
length-- Returns:
- a
StringValidatorthat generates an error if a string exceeds a maximum length
-
minimumLength
public static StringValidator minimumLength(int length)
- Parameters:
length-- Returns:
- a
StringValidatorthat generates an error if a string is not of a minimum length
-
lengthBetween
public static StringValidator lengthBetween(int minimum, int maximum)
- Parameters:
minimum-maximum-- Returns:
- a
StringValidatorthat generates an error if the length of a string is not between (inclusive) minimum and maximum
-
-