Description
Provides an extended TextField that performs
automated validation and conversion of user entered text into typed Objects.
The ValidField component is rendered as a HTML <input type="text"> field
and must be wrapped by a Form component.
Each ValidField is configured with a
validator which
checks the correctness of the user's input and performs the input text to
java Object translations. The Form tracks the state of
all its ValidFields using a validation
delegate.
Using the validation delegate you can determine whether all the form's fields
are valid and inform the user of any validation errors.
There are number of pluggable validators you can assign to a ValidField
including:
-
DateValidator
- validates date strings and allows a minimum and maximum date range to be set
-
EmailValidator
- validates email strings and allows a minimum and maximum length to be set
-
NumberValidator
- validates number strings and allows a minimum and maximum values to be set
-
PatternValidator
- validates text for a specified pattern
-
StringValidator
- validates string values and allows a minimum length to be set
The ValidField's
BaseValidator
classes automatically provide powerful client-side JavaScript field validation
when their parent Form is posted.
Validator client scripting is disabled by default. To enable the client
scripting explicitly set the "clientScriptingEnabled" property to true in
each validator. For example:
<bean name="emailValidator" class="org.apache.tapestry.valid.EmailValidator">
<set-property name="clientScriptingEnabled" expression="true"/>
<set-property name="minimumLength" expression="8"/>
<set-property name="required" expression="true"/>
</bean>
Note if a form includes a "Cancel" style submit button, the cancel button will
need to set the form's onsubmit event handler to null, so that the
JavaScript field validation is not invoked when the form is submitted.
For example:
<input jwcid="@Submit" listener="ognl:listeners.okSubmit" type="Submit" value=" OK "/>
<input jwcid="@Submit" listener="ognl:listeners.cancelSubmit" type="Submit" value="Cancel" onclick="form.onsubmit = null;"/>
|