HTML and CSS Reference
In-Depth Information
<br/>
<h:outputText value="Enter Number2: "/>
<h:inputText id="number2"
required="true"
value="#{testBean.number2}">
<f:validateLongRange minimum="0" maximum="999"/>
</h:inputText>
<h:message for="number2"/>
<br/>
<h:commandButton value="submit"/>
</h:form>
We have a form that contains two inputText components ( number1 and number2 ). Every inputText component
has two attached validators. Every input text has the following validators:
1. <f:validateRequired> , which is used to validate that the EditableValueHolder
component will not contain empty input (using the required="true" attribute has the
same effect).
2. <f:validateLongRange> , which is used to validate that the value of the long integer field is
within a specified range (minimum and maximum).
<f:validateLongRange> is used in the example to verify that both input texts have a minimum value equal
to 0 and a maximum value equal to 999 . If the user enters empty values or out-of-range values in both inputText
components and then clicks the "submit" command button, the user will see two validation error messages in
both <h:message/> components that are associated with every inputText component. This explains what we said
previously that the validation in JSF (like conversion) must be applied to every component that has one or more
validator(s).
Standard JSF Validators
Now, let's dive into the details of the JSF standard validators. Table 3-2 shows the JSF standard validators.
Table 3-2. JSF Standard Validators
Validator Tag
Description
<f:validateRequired>
Used to validate that the EditableValueHolder (such as input text) value is required.
Setting the required="true" attribute has the same effect.
<f:validateLongRange>
Used to validate that the EditableValueHolder value which is long integer is within
a specified range.
<f:validateDoubleRange>
Used to validate that the EditableValueHolder value which is double is within a
specified range.
<f:validateLength>
Used to validate that the EditableValueHolder value is within the specified length
range.
<f:validateRegex>
Used to validate that the EditableValueHolder value is complaint with a specified
Java regular expression.
<f:validateBean>
Used to assign the EditableValueHolder local value validation to the Java Bean
Validation (JSR 303) APIs.
 
 
Search WWH ::




Custom Search