You can set validation features for all Faces input components.
For example, you can set validation for an Input Date/Time component by setting
its minimum value to 2003/01/01 and its maximum values to "now".
Before you add validation to an input component:
- Create a dynamic Web project.
- Create a JSF enabled JSP file.
To add validation to an input component:
- In the Properties view for the Input component, select one of the
following formats from the list:
- String - Specifies that the input should be in the form of a text string.
For information on adding validation to a input string component, refer to
the online help topic Adding validation to an input string component.
- Number - Specifies that the input should be in the form of a number.
- Date/Time - Specifies that the input should be in the form of a date and/or
time.
- Mask - Specifies that the input be filtered in a way that selectively
includes or excludes certain values.
Once you have selected a format, you can further configure the format
from the options available in the Properties view.
- To validate the value entered in this field on the server, click
the Validation tab in the Properties view:
- To require the user to enter a value, select Value
is required.
- The validation has two options:
- Use simple validation - Allows you to set a minimum
and maximum number of character values for the input. When submitted to the
server, the input is validated to ensure it is within this range. The Constraint drop
down allows you select from a predefined set of regular expressions. The default
is blank (no constraint). Use the Click to create/edit custom validation
code to define a custom regular expression.
- Use advanced validation - Allows you to define
a validation using JSF expression syntax. When defining the constraint you
can use standard Java™ or Javascript regular expression syntax.
- Select Display validation error messages in an error
message control to automatically create a Display Error component
that displays an error message if validation fails on the input component.
Optionally, select Click to create/edit custom validation
code to switch to the Quick Edit view and create custom validation
code.
- To validate the value entered in this field on the client, click
the Behaviour tab in the Properties view:
- Select Validate field value in the browser.
- On the onblur Actions and onfocus
Actions tabs, for On success and On
failure select a class for the Apply CSS classes field
and select an action from the Run action list.
Optionally, click Additional behaviors can be supplied
in the onsuccess, onerror, onfocussuccess and onfocuserror events in the QuickEdit
view to create custom behaviour code.
- Add a Submit button to the page using the Button - Commandcomponent
on the Palette.
- Save the page.
You can test the validation by running the page on the server (right-click
the page in Page Designer and select Run on Server.