Advanced Java (2160707)

BE | Semester-4   Winter-2018 | 20-11-2018

Q5) (c)

List the JSF validation tags and explain any two.

  • JSF provides inbuilt validators to validate its UI components. These tags can validate the length of the field, the type of input which can be a custom object
  • For these tags you need to use the following namespaces of URI in html node <html xmlns="" xmlns:f="">

JSF Validation Tags

Sr Validation Tag Description
1 f:validateLength Validates length of a string <f:validateLength minimum="10" maximum="15" />
2 f:validateLongRange Validates range ofnumeric value <f:validateLongRange minimum="10" maximum="15" />
3 f:validateDoubleRange Validates range of float value <f:validateDoubleRange minimum="1000.00" maximum="100000.00" />
4 f:validateRegex Validate JSF component with a given regular expression. < f:validateRegex pattern="((?=.*[a-z]).{6,})" />
5 Custom Validator Creating a custom validator
  1. Create a validator class by implementing javax.faces.validator.Validator interface.
  2. Implement validate() method of above interface.
  3. Use Annotation @FacesValidator to assign a unique id to the custom validator.