org.apache.tapestry5.corelib.components.TextField.xdoc Maven / Gradle / Ivy
Show all versions of tapestry-core Show documentation
Once again, we're basing the example on the order payment screen
from the
Radio
examples. This time we're focusing in on
the text field used for entering the credit card number, and we're going to validate
that number using a regular expression:
The validate parameter is used to specify validations for the field. When it is omitted,
the @Validate annotation of the property is used (if present). In any case, this references
two of the built-in validations: "required" and "regexp".
This example presumes that the Payment page includes a property named "cardNumber".
The "required" validation requires no extra configuration. On the other hand, "regexp"
needs to know the regular expression to enforce ... and it should also have a
user presentable message.
Tapestry uses the page's message catalog as a source of extra validation information.
The key is the component id, the name of the validation. The value is given to the validator
object ... here it's the regular expression for a credit card number (four sets of four digits,
optionally seperated by dashes). The "-message" entry allows the normal error message
for the validator to be overridden.
These same approaches apply consistently to all form control element components.