Class StringValidator
- java.lang.Object
-
- org.apache.wicket.behavior.Behavior
-
- org.apache.wicket.validation.validator.AbstractRangeValidator<Integer,String>
-
- org.apache.wicket.validation.validator.StringValidator
-
- All Implemented Interfaces:
Serializable
,IComponentAwareEventSink
,IComponentAwareHeaderContributor
,IClusterable
,IValidator<String>
public class StringValidator extends AbstractRangeValidator<Integer,String>
Validator for checking if length of a string falls within [min,max] range. If either min or max arenull
they are not checked.If the component is attached to an
input
tag, amaxlen
attribute will be added if the maximum is set. *Resource keys:
StringValidator.exact
if min==max (exactLength(int)
)StringValidator.range
if both min and max are notnull
StringValidator.minimum
if max isnull
(minimumLength(int)
)StringValidator.maximum
if min isnull
(maximumLength(int)
)
Error Message Variables:
name
: the id ofComponent
that failedlabel
: the label of theComponent
(either comes fromFormComponent.labelModel
or 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 protected
StringValidator()
Constructor used for subclasses who want to set the range usingAbstractRangeValidator.setRange(Comparable, Comparable)
StringValidator(Integer minimum, 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 IValidationError
decorate(IValidationError error, IValidatable<String> validatable)
Allows subclasses to decorate reported errorsstatic StringValidator
exactLength(int length)
protected Integer
getValue(IValidatable<String> validatable)
Gets the value that should be validated against the rangeprotected boolean
hasLengthAttribute(String tagName)
static StringValidator
lengthBetween(int minimum, int maximum)
static StringValidator
maximumLength(int length)
static StringValidator
minimumLength(int length)
void
onComponentTag(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(Integer minimum, 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 Integer getValue(IValidatable<String> validatable)
Description copied from class:AbstractRangeValidator
Gets the value that should be validated against the range- Specified by:
getValue
in classAbstractRangeValidator<Integer,String>
- Returns:
- value to validate
-
decorate
protected IValidationError decorate(IValidationError error, IValidatable<String> validatable)
Description copied from class:AbstractRangeValidator
Allows subclasses to decorate reported errors- Overrides:
decorate
in classAbstractRangeValidator<Integer,String>
- Returns:
- decorated error
-
onComponentTag
public void onComponentTag(Component component, ComponentTag tag)
Description copied from class:Behavior
Called any time a component that has this behavior registered is rendering the component tag.- Overrides:
onComponentTag
in classBehavior
- Parameters:
component
- the component that renders this tag currentlytag
- the tag that is rendered
-
hasLengthAttribute
protected boolean hasLengthAttribute(String tagName)
-
exactLength
public static StringValidator exactLength(int length)
- Parameters:
length
-- Returns:
- a
StringValidator
that generates an error if a string is not of an exact length
-
maximumLength
public static StringValidator maximumLength(int length)
- Parameters:
length
-- Returns:
- a
StringValidator
that generates an error if a string exceeds a maximum length
-
minimumLength
public static StringValidator minimumLength(int length)
- Parameters:
length
-- Returns:
- a
StringValidator
that 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
StringValidator
that generates an error if the length of a string is not between (inclusive) minimum and maximum
-
-