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 arenull
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:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
AbstractRangeValidator.Mode
Validator mode
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractRangeValidator()
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
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected IValidationError
decorate(IValidationError error, IValidatable<V> validatable)
Allows subclasses to decorate reported errorsR
getMaximum()
Gets the maximum value.R
getMinimum()
Gets the minimum value.AbstractRangeValidator.Mode
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 void
setRange(R minimum, R maximum)
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 Detail
-
AbstractRangeValidator
public AbstractRangeValidator(R minimum, R maximum)
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 Detail
-
setRange
protected final void setRange(R minimum, R maximum)
Sets validator range- Parameters:
minimum
-maximum
-
-
validate
public void validate(IValidatable<V> validatable)
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
protected abstract R getValue(IValidatable<V> validatable)
Gets the value that should be validated against the range- Parameters:
validatable
-- Returns:
- value to validate
-
getMinimum
public R getMinimum()
Gets the minimum value.- Returns:
- minimum value
-
getMaximum
public R getMaximum()
Gets the maximum value.- Returns:
- maximum value
-
decorate
protected IValidationError decorate(IValidationError error, IValidatable<V> validatable)
Allows subclasses to decorate reported errors- Parameters:
error
-validatable
-- Returns:
- decorated error
-
getMode
public final AbstractRangeValidator.Mode getMode()
Gets validation mode which is determined by whether min, max, or both values are provided- Returns:
- validation mode
-
-