Java Reference
In-Depth Information
standard validator tags in the JSF Core Tag Library or create custom validators. Table 33.2
lists some JSF input validator tags.
T ABLE 33.2
JSF Input Validator Tags
JSF Tag
Description
validates the length of the input.
f:validateLength
validates whether numeric input falls within acceptable range of double values.
f:validateDoubleRange
f:validateLongRange
validates whether numeric input falls within acceptable range of long values.
f:validateRequired
validates whether a field is not empty.
f:validateRegex
validates whether the input matches a regualar expression.
invokes a custom method in a bean to perform custom validation.
f:validateBean
Consider the following example that displays a form for collecting user input as shown in
Figure 33.16. All text fields in the form must be filled. If not, error messages are displayed.
The SSN must be formatted correctly. If not, an error is displayed. If all input are correct,
clicking Submit displays the result in an output text, as shown in Figure 33.17.
(a) The required messages are displayed if input is required, but empty.
(b) Error messages are displayed if input is incorrect.
F IGURE 33.16
The input fields are validated.
Here are the steps to create this project.
Step 1. Create a new page in Listing 33.11, ValidateForm.xhtml.
Step 2. Create a new managed bean named validateForm , as shown in Listing 33.12.
 
 
Search WWH ::




Custom Search