# Creating and Registering Validation Rule Classes

Use the Registered Rules page of the Business Components Project Editor to create or add validation rules to your project. This page displays the registered validation rules already defined. These rules are stored as a list with the project's XML-definition (`.jpx` file). Registered rules can be applied to an Entity Object or an Entity attribute as a validation rule.

Field | Description
Registered Validation Rules | The list of rules contained by the project.
Create | Click Create to open the New Class dialog box where you can create a new registered validation rule for your project, and specify class and style information for the rule. This information will be used to generate skeleton code for the rule and will add a new Java file to the project. Custom validation logic can then be implemented in the `validateValue` method of the class. Since this new class is a JavaBean, new properties (generated in the class) could be added to the Java class. Note: At the time of applying the rule to a particular level, newly defined rules have to be compiled before property values can be declared for them.
Add | Click a registered rule name in the Registered Validation Rules list and click Add to add it to the project.
Remove | Click a rule name in the Registered Validation Rules list and click Remove to delete it from the project. Note that if the rule has already been applied at some level, that information is still valid.

#### To create and register a new validation rule class:

The following steps show how to create and register a validation rule based on a Business Component validation class. The Business Components for Java framework provides several validation classes, and you can implement custom validation classes.

1. In the Workspace view of the Navigator, right-click the Business Component for Java project file, then choose Edit. The Business Component Project Wizard opens.

2. Open the Registered Rules tab, and click New. The Validation Rule Wizard opens.

3. In the Validation Rule Wizard, enter the class name for the rule and the name of the package where it should reside. Enter the fully qualified class name in the Extends field if the validator extends the functionality of an existing class. You can accept the default or click Browse to choose a different class.

4. Click OK to close the Validation Rule Wizard. Click Finish to exit the Business Component Project Wizard.

The Business Component for Java framework generates code and registers the new validator type. The new validator name will appear in other wizards and you can apply it to entities and attributes as you would any other rule.

#### To add existing validation classes to your project:

1. In the Workspace tab of the Navigation panel, right-click the Business Components for Java project file, then choose Edit. The Business Component Project Wizard opens.

2. Open the Registered Rules tab, and click Add. The Register a Java Class as a Rule dialog box opens.

3. By default, the Register a Java Class as a Rule dialog box displays the `JboGenericVaildator` class, and the Description field lists `Temporary`. You can either enter a class name or click the Browse button to select a class. Note, if you enter the name of a class, you must ensure that it implements the `JbiValidator` class.

   If you click Browse, the Find Superclass dialog opens. This dialog uses a tree structure to display the classes from which you can choose.

   Note that one of the classes, `oracle.jbo.server.rules`, contains the Business Component validator classes. For more information on these classes, see Business Component Validator Classes.

   Select the class you want to use and click OK. The Register a Java Class dialog displays the class name in the Class field and its definition in the Description box.

   Some validator types can be customized. If the Edit Validation Rules panel is available, you can enter data in the table of Properties and Values to specify parameters for the validator. (If the validator is a JavaBean with its own customizer, that customizer will display.)

4. Click OK to close the dialog and Finish to close the wizard.

The Business Components for Java framework generates code and registers the new validator type. The new validator name will appear in other wizards and you can apply it to entities and attributes as you would any other rule.

#### Business Component Validator Classes

Following are the Business Components validator classes in `oracle.jbo.server.rules`. You can use these directly, or as the basis for a custom validator type.

Class | Description
`JboCompareValidator` | Performs logical comparisons with literals.
`JboSQLCompareValidator` | Performs logical comparisons with the result of a SQL statement.
`JboQOCompareValidator` | Performs logical comparisons with the result of a View Object's query.
`JboRangeValidator` | Performs range comparisons with literals.
`JboListValidator` | Checks that a value is one of the list.
`JboQOListValidator` | Checks that the value is one of the list returned by executing this View Object. This may be used for LOVs.
`JboSQLListValidator` | Checks that the value is in the list returned by executing a SQL statement.
`JboMethodValidator` | Used to invoke user-defined methods.