Standard Validators in JSF

Standard Validators in JSF
The input provided by the user must be validated before processing it to the next step. Like checking the contact number, name should contain only alphabets etc.

JSF has built-in validators that is used to perform different types of DataValidation. These validators are known as Standard Validators and the tags are provided by Core tag library in JSF.

Standard Validators

 

validateDoubleRange validateLongRange validateLength validateRequired validateRegex
Used to validate Range of double inputs Used to validate Range of Long inputs Used to validate Length Similar to required attribute of UI Component Used to validate input against specified pattern

ValidatorMessage:
When we use these validators and if the user input is wrong, the system will show an error message to the user which is of system format and user wont be able to understand. To overcome this we use ValidatorMessage to give the error message in understandable format for the user.

Example:
Lets get the input from User and validate it using the above Standard Validators
Name – Should contain only Alphabets and no numbers
phone – Should have 10 numbers
Amount- Should be between 200 and 5000
Credit Card – Required Field

JSF Managed Bean – Customer.java

Input.xhtml

Output:
output1

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *