Class AbstractRangeValidator<R extends Comparable<? super R> & Serializable,V extends Serializable>
java.lang.Object
org.apache.wicket.behavior.Behavior
org.apache.wicket.validation.validator.AbstractRangeValidator<R,V>
- Type Parameters:
R
- type of range valueV
- type of validatable
- All Implemented Interfaces:
Serializable
,IComponentAwareEventSink
,IComponentAwareHeaderContributor
,IClusterable
,IValidator<V>
- Direct Known Subclasses:
RangeValidator
,StringValidator
public abstract class AbstractRangeValidator<R extends Comparable<? super R> & Serializable,V extends Serializable>
extends Behavior
implements IValidator<V>
Base class for validators that check if a given value falls within [min,max] range.
If either min or max are
null
they are not checked.
Resource keys:
<class.simpleName>.exact
if min==max<class.simpleName>.range
if both min and max are notnull
<class.simpleName>.minimum
if max isnull
<class.simpleName>.maximum
if min isnull
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 valueminimum
: the minimum allowed valuemaximum
: the maximum allowed value
- Author:
- igor
- See Also:
-
Nested Class Summary
-
Constructor Summary
ModifierConstructorDescriptionprotected
Constructor used for subclasses who want to set the range usingsetRange(Comparable, Comparable)
AbstractRangeValidator
(R minimum, R maximum) Constructor that sets the minimum and maximum values. -
Method Summary
Modifier and TypeMethodDescriptionprotected IValidationError
decorate
(IValidationError error, IValidatable<V> validatable) Allows subclasses to decorate reported errorsGets the maximum value.Gets the minimum value.getMode()
Gets validation mode which is determined by whether min, max, or both values are providedprotected abstract R
getValue
(IValidatable<V> validatable) Gets the value that should be validated against the rangeprotected final void
Sets validator rangevoid
validate
(IValidatable<V> validatable) Validates theIValidatable
instance.Methods inherited from class org.apache.wicket.behavior.Behavior
afterRender, beforeRender, bind, canCallListener, detach, getStatelessHint, isEnabled, isTemporary, onAttribute, onComponentTag, onConfigure, onEvent, onException, onRemove, onTag, renderHead, unbind
-
Constructor Details
-
AbstractRangeValidator
Constructor that sets the minimum and maximum values.- Parameters:
minimum
- the minimum valuemaximum
- the maximum value
-
AbstractRangeValidator
protected AbstractRangeValidator()Constructor used for subclasses who want to set the range usingsetRange(Comparable, Comparable)
-
-
Method Details
-
setRange
Sets validator range- Parameters:
minimum
-maximum
-
-
validate
Description copied from interface:IValidator
Validates theIValidatable
instance. Validation errors should be reported using theIValidatable.error(IValidationError)
method.- Specified by:
validate
in interfaceIValidator<R extends Comparable<? super R> & Serializable>
- Parameters:
validatable
- theIValidatable
instance being validated
-
getValue
Gets the value that should be validated against the range- Parameters:
validatable
-- Returns:
- value to validate
-
getMinimum
Gets the minimum value.- Returns:
- minimum value
-
getMaximum
Gets the maximum value.- Returns:
- maximum value
-
decorate
Allows subclasses to decorate reported errors- Parameters:
error
-validatable
-- Returns:
- decorated error
-
getMode
Gets validation mode which is determined by whether min, max, or both values are provided- Returns:
- validation mode
-