|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objecteu.webtoolkit.jwt.WObject
eu.webtoolkit.jwt.WValidator
public class WValidator
A validator is used to validate user input according to pre-defined rules.
A validator may be associated with a form widget using
WFormWidget#setValidator().
The validator validates the user input. A validator may have a split
implementation to provide both validation at the client-side (which gives
instant feed-back to the user while editing), and server-side validation (to
be sure that the client was not tampered with). The feed-back given by
(client-side and server-side) validation is reflected in the style class of
the form field: a style class of Wt-invalid is set for a field
that is invalid.
This WValidator only checks that mandatory fields are not empty. This class
is reimplemented in WDateValidator, WIntValidator,
WDoubleValidator, WLengthValidator and
WRegExpValidator. All these validators provibe both client-side and
server-side validation.
If these validators are not suitable, you can inherit from this class, and
provide a suitable implementation to validate() which does the server-side validation. If you want to provide
client-side validation for your own validator, you may also reimplement
getJavaScriptValidate().
The strings used in this class can be translated by overriding the default values for the following localization keys:
WValidator.State.Invalid: This field cannot be empty
WFormWidget| Nested Class Summary | |
|---|---|
static class |
WValidator.Result
A class that holds a validation result. |
static class |
WValidator.State
The state in which validated input can exist. |
| Constructor Summary | |
|---|---|
WValidator()
Creates a new validator. |
|
WValidator(boolean mandatory)
Creates a new validator. |
|
WValidator(boolean mandatory,
WObject parent)
Creates a new validator. |
|
WValidator(WObject parent)
Creates a new validator. |
|
| Method Summary | |
|---|---|
void |
fixup(java.lang.CharSequence input)
This function attempts to change input to be valid according to the validator's rules. |
java.lang.String |
getInputFilter()
Returns a regular expression that filters input. |
WString |
getInvalidBlankText()
Returns the message displayed when a mandatory field is left blank. |
java.lang.String |
getJavaScriptValidate()
Creates a Javascript object that validates the input. |
boolean |
isMandatory()
Returns if input is mandatory. |
void |
setInvalidBlankText(java.lang.CharSequence text)
Sets the message to display when a mandatory field is left blank. |
void |
setMandatory(boolean mandatory)
Sets if input is mandatory. |
WValidator.Result |
validate(java.lang.String input)
Validates the given input. |
| Methods inherited from class eu.webtoolkit.jwt.WObject |
|---|
addChild, getId, getObjectName, remove, setObjectName, tr |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public WValidator(WObject parent)
public WValidator()
Calls this((WObject)null)
public WValidator(boolean mandatory,
WObject parent)
Indicate whether input is mandatory.
setMandatory(boolean mandatory)public WValidator(boolean mandatory)
Calls this(mandatory, (WObject)null)
| Method Detail |
|---|
public void setMandatory(boolean mandatory)
When an input is not mandatory, then an empty field is always valid.
public boolean isMandatory()
public void setInvalidBlankText(java.lang.CharSequence text)
The default value is "This field cannot be empty".
public WString getInvalidBlankText()
setInvalidBlankText(CharSequence text)public void fixup(java.lang.CharSequence input)
In general the function needs not to change the input into a valid input. The default implementation does nothing. But it may help the user in getting its input right.
public WValidator.Result validate(java.lang.String input)
Note: The signature for this method changed in JWt 3.2.0.
public java.lang.String getJavaScriptValidate()
The JavaScript expression should evaluate to an object which contains a
validate(text) function, which returns an object that
contains the following two fields:
message that indicates the problem if not valid.Returns an empty string if the validator does not provide a client-side validation implementationq.
Note: The signature and contract changed changed in JWt 3.1.9.
getInputFilter()public java.lang.String getInputFilter()
The returned regular expression is used to filter keys presses. The regular expression should accept valid single characters.
For details on valid regular expressions, see WRegExpValidator.
As an example, "[0-9]" would only accept numbers as valid
input.
The default implementation returns an empty string, which does not filter any input.
getJavaScriptValidate()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||