Java Reference
In-Depth Information
F IGURE 33.17
The correct input values are displayed.
L ISTING 33.11
ValidateForm.xhtml
1 <?xml version='1.0' encoding='UTF-8' ?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
3 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4 <html xmlns="http://www.w3.org/1999/xhtml"
5 xmlns:h="http://xmlns.jcp.org/jsf/html"
6 xmlns:f="http://xmlns.jcp.org/jsf/core">
7 <h:head>
8 <title>Validate Form</title>
9 </h:head>
10 <h:body>
11 <h:form>
12 <h:panelGrid columns="3">
13 <h:outputLabel value="Name:"/>
14 <h:inputText id="nameInputText" required="true"
15 requiredMessage="Name is required"
16 validatorMessage="Name must have 1 to 10 chars"
17 value="#{validateForm.name}">
18 <f:validateLength minimum="1" maximum="10" />
19 </h:inputText>
20
required input
required message
validator message
validate length
<h:message for="nameInputText" style="color:red"/>
message element
21
22 <h:outputLabel value="SSN:" />
23 <h:inputText id="ssnInputText" required="true"
24 requiredMessage="SSN is required"
25 validatorMessage="Invalid SSN"
26 value="#{validateForm.ssn}">
27 <f:validateRegex pattern="[\d]{3}-[\d]{2}-[\d]{4}"/>
28 </h:inputText>
29
validate regex
<h:message for="ssnInputText" style="color:red"/>
30
31 <h:outputLabel value="Age:" />
32 <h:inputText id="ageInputText" required="true"
33 requiredMessage="Age is required"
34 validatorMessage="Age must be between 16 and 120"
35 value="#{validateForm.ageString}">
36 <f:validateLongRange minimum="16" maximum="120"/>
37 </h:inputText>
38 <h:message for="ageInputText" style="color:red"/>
39
40 <h:outputLabel value="Height:" />
validate integer range
 
 
Search WWH ::




Custom Search