public class StringValidator extends AbstractRangeValidator<Integer,String>
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 not null
StringValidator.minimum
if max is null
(minimumLength(int)
)StringValidator.maximum
if min is null
(maximumLength(int)
)Error Message Variables:
name
: the id of Component
that failedlabel
: the label of the Component
(either comes from
FormComponent.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 lengthAbstractRangeValidator.Mode
Modifier | Constructor and Description |
---|---|
protected |
StringValidator()
Constructor used for subclasses who want to set the range using
AbstractRangeValidator.setRange(Comparable, Comparable) |
|
StringValidator(Integer minimum,
Integer maximum)
Constructor that sets the minimum and maximum length values.
|
Modifier and Type | Method and Description |
---|---|
protected IValidationError |
decorate(IValidationError error,
IValidatable<String> validatable)
Allows subclasses to decorate reported errors
|
static StringValidator |
exactLength(int length) |
protected Integer |
getValue(IValidatable<String> validatable)
Gets the value that should be validated against the range
|
protected 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.
|
getMaximum, getMinimum, getMode, setRange, validate
afterRender, beforeRender, bind, canCallListenerInterface, detach, getStatelessHint, isEnabled, isTemporary, onConfigure, onEvent, onException, onRemove, renderHead, unbind
public StringValidator(Integer minimum, Integer maximum)
minimum
- the minimum lengthmaximum
- the maximum lengthprotected StringValidator()
AbstractRangeValidator.setRange(Comparable, Comparable)
protected Integer getValue(IValidatable<String> validatable)
AbstractRangeValidator
getValue
in class AbstractRangeValidator<Integer,String>
protected IValidationError decorate(IValidationError error, IValidatable<String> validatable)
AbstractRangeValidator
decorate
in class AbstractRangeValidator<Integer,String>
public void onComponentTag(Component component, ComponentTag tag)
Behavior
onComponentTag
in class Behavior
component
- the component that renders this tag currentlytag
- the tag that is renderedprotected boolean hasLengthAttribute(String tagName)
public static StringValidator exactLength(int length)
length
- StringValidator
that generates an error if a string is not of an exact
lengthpublic static StringValidator maximumLength(int length)
length
- StringValidator
that generates an error if a string exceeds a maximum
lengthpublic static StringValidator minimumLength(int length)
length
- StringValidator
that generates an error if a string is not of a minimum
lengthpublic static StringValidator lengthBetween(int minimum, int maximum)
minimum
- maximum
- StringValidator
that generates an error if the length of a string is not
between (inclusive) minimum and maximumCopyright © 2006–2019 Apache Software Foundation. All rights reserved.