Validation rules
The Validator interface works by invoking a series of rules, and comparing entered data values against the rules. Each rule is an executable Java™ file that implements the Rule interface.
The validation plug-in supports two types of rules.
- ROW: row-level rules are executed first.
- GRID: grid-level rules are executed after row-level rules.
When a user saves data for a grid that uses a given validation plug-in, all of the rules are applied. The row-level rules are applied first, followed by the grid-level rules. Rules are applied in the order they are declared in the rules file.
Data validation rules file structure
A validation rules file is an XML file that contains one or more rules. Each rule can contain the following tags.
Tag | Description |
---|---|
rule | Begins the rule and sets the rule type, which can be either ROW or GRID. |
name | The name of the rule. |
desc | A text description of the rule. |
enable | A boolean value for enabling or disabling the rule:
|
applies-to-tvc-id | The internal name of the grid component for which the rule applies. To apply the rule to multiple grids, use a separate applies-to-tvc-id tag for each grid component. This tag is optional; if omitted, the rule is applied to all grids on the specified form. |
class | The Java class containing the commands for processing the rule. To use the sample range check rule, you enter: com.unicacorp.uap.grid.validation.rule.basic.RangeCheckRule |
set-property | The set-property tag passes parameters to the rules. Each rule can contain zero or more set-property tags. |
Sample data validation rules
HCL® Marketing Operations ships with the following sample rules.
Rule | Description |
---|---|
BeginsWithRule | Ensures the text column being validated begins with the specified character. You set the beginCharacter and column properties. For example: This rule checks the Name field in the dyn_vendors database table to make sure that the value begins with the letter A. Class name: com.unicacorp.uap.grid.validation.rule.basic.BeginsWithRule |
DateCheckRule | Ensures the date column being validated falls within the specified range. Set the following properties: greaterThan, lessThan, column. For example:
This rule checks the invoiceDate field in the dyn_vendors database table to make sure that the value is not before the year 2000. Optionally, you can also set the dateFormat property. If you add this property, dates must be entered in the specified format. You can set the following format values: dd/MM/yyyy, MM/dd/yyyy, dd/MM/yy, MM/dd/yy, yyyy-MM-dd, yyyy.MM.dd Class name: com.unicacorp.uap.grid.validation.rule.basic.DateCheckRule |
RangeCheckRule | Ensures the integer column being validated falls within the specified range. You set the following properties: minValue, maxValue, column For example:
This rule checks the numEmployees field in the dyn_vendors database table to make sure that the value is between 1 and 999,999. Class name: com.unicacorp.uap.grid.validation.rule.basic.RangeCheckRule |
UniqueCheckRule | Ensures that the column being validated does not contain duplicate values. You set the column property. Class name: com.unicacorp.uap.grid.validation.rule.basic.UniqueCheckRule Note: This
rule is always applied across the entire grid, even if you use ROW
to indicate that this is a row-level rule. |