|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectwicket.markup.html.form.validation.AbstractValidator
wicket.markup.html.form.validation.StringValidator
wicket.markup.html.form.validation.PatternValidator
public class PatternValidator
Validates 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 MetaPatternfor details.
The error message will be generated with the key "PatternValidator" and the messages keys that can be used are:
Pattern,
MetaPattern,
Serialized Form| Constructor Summary | |
|---|---|
PatternValidator(MetaPattern pattern)
Constructor. |
|
PatternValidator(java.util.regex.Pattern pattern)
Constructor. |
|
PatternValidator(java.lang.String pattern)
Constructor. |
|
PatternValidator(java.lang.String pattern,
int flags)
Constructor. |
|
| Method Summary | |
|---|---|
java.util.regex.Pattern |
getPattern()
Gets the regexp pattern. |
protected java.util.Map |
messageModel(FormComponent formComponent)
Gets the default variables for interpolation. |
void |
onValidate(FormComponent formComponent,
java.lang.String value)
Validates the set pattern. |
protected java.lang.String |
resourceKey(FormComponent formComponent)
Gets the resource key for validator's error message from the ApplicationSettings class. |
java.lang.String |
toString()
|
| Methods inherited from class wicket.markup.html.form.validation.StringValidator |
|---|
exactLength, lengthBetween, maximumLength, minimumLength, validate |
| Methods inherited from class wicket.markup.html.form.validation.AbstractValidator |
|---|
error, error, error, error |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public PatternValidator(java.lang.String pattern)
pattern - Regular expression pattern
public PatternValidator(java.lang.String pattern,
int flags)
pattern - Regular expression patternflags - Compile flags for java.util.regex.Patternpublic PatternValidator(java.util.regex.Pattern pattern)
pattern - Java regex patternpublic PatternValidator(MetaPattern pattern)
pattern - MetaPattern pattern| Method Detail |
|---|
public void onValidate(FormComponent formComponent,
java.lang.String value)
onValidate in class StringValidatorformComponent - form componentvalue - The string value to validateStringValidator.onValidate(wicket.markup.html.form.FormComponent,String)public final java.util.regex.Pattern getPattern()
protected java.util.Map messageModel(FormComponent formComponent)
AbstractValidator
messageModel in class AbstractValidatorformComponent - form component
protected java.lang.String resourceKey(FormComponent formComponent)
AbstractValidator
resourceKey in class AbstractValidatorformComponent - form component that is being validated
AbstractValidator.resourceKey(wicket.markup.html.form.FormComponent)public java.lang.String toString()
toString in class java.lang.ObjectObject.toString()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||