...
Validator | Constraint Type | Description | Example |
---|---|---|---|
– | Ensures that the given input looks like a valid e-mail address |
| |
max | long | Enforces a maximum integer value |
|
maxLength | int | Makes sure that a string value has a maximum length |
|
min | long | Enforces a minimum integer value |
|
minLength | int | Makes sure that a string value has a minimum length |
|
none | – | Does nothing (used to override a @Validate annotation) |
|
regexp | pattern | Makes sure that a string value conforms to a given pattern |
|
required | – | Makes sure that a string value is not null and not the empty string |
|
...
HTML5 Client-side Validation
When the "the tapestry.enable-html5-support
" symbol is set to true (it is false by default), the Tapestry's built-in validators will automatically add enable the appropriate HTML5-specific "type" and validation attributes to the rendered HTML of Tapestry's form components, triggering the HTML5 client-side validation behavior built into most modern browsers. For example, if you use the "email" validatorand "required" validators, like this:
Code Block |
---|
<t:textfield value="user.emailAddress" validate="email,required" /> |
then the output HTML will look like this:
Code Block |
---|
<input type="email" required ...> |
which causes modern browsers to present a validation error message whenever text is entered that doesn't look like an email address, or if the field is left blank.
The browser's built-in validation is performed before Tapestry's own client-side validation. This is so that older browsers will still perform client-side validation as expected.
The following behaviors are includedThe following HTML5 validation behaviors are enabled:
- The "required" validator adds the "required" attribute to the rendered HTML
- The "regexp" validator adds the "pattern" attribute to the rendered HTML
- The "email" validator sets the
type
attribute to "email" in the rendered HTML - The "min" validator sets the
type
attribute to "number" and adds the "min" attribute in the rendered HTML - The "max" validator sets the
type
attribute to "number" and adds the "max" attribute in the rendered HTML - When bound to a number type, the TextField component sets the
type
attribute to "number" in the rendered HTML
...