|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.apache.wicket.behavior.Behavior
org.apache.wicket.validation.validator.AbstractValidator<String>
org.apache.wicket.validation.validator.StringValidator
org.apache.wicket.validation.validator.PatternValidator
public class PatternValidator
Validates a Component by matching the component's value against a regular expression
pattern. A PatternValidator can be constructed with either a Java regular expression
(compiled or not) or a MetaPattern. If the pattern matches against the value of the
Component it is attached to when validate is called by the framework,
then that input value is considered valid. If the pattern does not match, the
errorMessage method will be called.
For example, to restrict a field to only digits, you might add a PatternValidator
constructed with the pattern "\d+". Another way to do the same thing would be to construct the
PatternValidator passing in MetaPattern.DIGITS. The advantages of using
MetaPattern over straight Java regular expressions are that the patterns are easier
to construct and easier to combine into complex patterns. They are also more readable and more
reusable. See MetaPattern for
details.
The error message will be generated with the key "PatternValidator" and the message keys that can be used are:
Component that failedComponent - either comes from
FormComponent.labelModel or resource key [form-id].[form-component-id] in that order
Pattern,
MetaPattern,
Serialized Form| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class org.apache.wicket.validation.validator.StringValidator |
|---|
StringValidator.ExactLengthValidator, StringValidator.LengthBetweenValidator, StringValidator.MaximumLengthValidator, StringValidator.MinimumLengthValidator |
| Constructor Summary | |
|---|---|
PatternValidator(MetaPattern pattern)
Constructor that accepts a MetaPattern argument. |
|
PatternValidator(Pattern pattern)
Constructor that accepts a Java regex Pattern argument. |
|
PatternValidator(String pattern)
Constructor that accepts a String regular expression pattern. |
|
PatternValidator(String pattern,
int flags)
Constructor that accepts a String pattern and Java regex compile
flags as arguments. |
|
| Method Summary | |
|---|---|
Pattern |
getPattern()
Gets the regexp pattern. |
protected void |
onValidate(IValidatable<String> validatable)
Checks a value against this PatternValidator's Pattern. |
PatternValidator |
setReverse(boolean reverse)
If set to true then input that matches the pattern is considered invalid. |
String |
toString()
|
protected Map<String,Object> |
variablesMap(IValidatable<String> validatable)
Checks a value against this PatternValidator's Pattern. |
| Methods inherited from class org.apache.wicket.validation.validator.StringValidator |
|---|
exactLength, lengthBetween, maximumLength, minimumLength |
| Methods inherited from class org.apache.wicket.validation.validator.AbstractValidator |
|---|
error, error, error, error, resourceKey, validate, validateOnNullValue |
| Methods inherited from class org.apache.wicket.behavior.Behavior |
|---|
afterRender, beforeRender, bind, canCallListenerInterface, canCallListenerInterface, detach, getStatelessHint, isEnabled, isTemporary, onComponentTag, onConfigure, onEvent, onException, renderHead, unbind |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public PatternValidator(String pattern)
String regular expression pattern.
pattern - a regular expression pattern
public PatternValidator(String pattern,
int flags)
String pattern and Java regex compile
flags as arguments.
pattern - a regular expression patternflags - compile flags for java.util.regex.Patternpublic PatternValidator(Pattern pattern)
regex Pattern argument.
pattern - a Java regex Patternpublic PatternValidator(MetaPattern pattern)
MetaPattern argument.
pattern - a MetaPattern| Method Detail |
|---|
public final Pattern getPattern()
public PatternValidator setReverse(boolean reverse)
reverse -
protected Map<String,Object> variablesMap(IValidatable<String> validatable)
PatternValidator's Pattern.
variablesMap in class AbstractValidator<String>validatable - the IValidatable to check
Map of variables for variable interpolationpublic String toString()
toString in class ObjectObject.toString()protected void onValidate(IValidatable<String> validatable)
PatternValidator's Pattern.
onValidate in class AbstractValidator<String>validatable - the IValidatable to check
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||