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>
Validator for checking if length of a string falls within [min,max] range.
If either min or max are
null
they are not checked.
If the component is attached to an input
tag, a maxlen
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:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.wicket.validation.validator.AbstractRangeValidator
AbstractRangeValidator.Mode
-
Constructor Summary
ModifierConstructorDescriptionprotected
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
Modifier and TypeMethodDescriptionprotected 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 Details
-
StringValidator
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 Details
-
getValue
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
Description copied from class:AbstractRangeValidator
Allows subclasses to decorate reported errors- Overrides:
decorate
in classAbstractRangeValidator<Integer,
String> - Returns:
- decorated error
-
onComponentTag
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
-
exactLength
- Parameters:
length
-- Returns:
- a
StringValidator
that generates an error if a string is not of an exact length
-
maximumLength
- Parameters:
length
-- Returns:
- a
StringValidator
that generates an error if a string exceeds a maximum length
-
minimumLength
- Parameters:
length
-- Returns:
- a
StringValidator
that generates an error if a string is not of a minimum length
-
lengthBetween
- Parameters:
minimum
-maximum
-- Returns:
- a
StringValidator
that generates an error if the length of a string is not between (inclusive) minimum and maximum
-