Creating an Event Handler

You can use an event handler to customize the behavior of a model.

The Design Tool offers a variety of features that assist you in creating event handlers. The result is a Java class that conforms to rules for event handling. This class is then mapped (attached) to specific objects of a model to customize its behavior.

You can attach event handlers to events associated with the entire model, a life cycle event, or to entities, attributes, operations, recordsets and recordset fields, and procedures. You can reuse a handler in multiple models or with multiple objects of the same type within the same model.

To create an event handler:

  1. Navigate to the object in the model that relates to the behavior in the model that you want to extend or override.
  2. Use the New Event Handler dialog box to generate a basic template that includes the supported events for that handler type.
  3. Edit the template in your default editor to add the event functionality. Methods for all supported events are included in the template, but they are commented out (disabled). Enable the event by defining the corresponding method.
  4. Rebuild the model JAR or .NET application extension file. Once the class is in the model JAR or .NET application extension file, it can be mapped to a model object. You can repeat the rebuild at any time, even if the event handler is already attached to an object.
  5. Attach the handler to the selected object in the model. You can attach the same handler to multiple objects. No rebuild is required.

The procedure for testing the event handler will vary according to the type of event you are creating.

Build Event Handlers For Check-in To Source Control

A commandline utility is now available to build event handlers on a 7.0 Windows Development Kit installation. Close the Design Tool before running the following batch files.

In the VHI\bin directory, there are two files:

The batch files each take a single argument. The argument is a path to the directory containing the model with event handlers.

Working With Existing Models

To use the cleaneventhandlers.bat file with existing models from VHI 6.6 or earlier, you can either copy the new build.xml from <VHI install folder>\lib\scripts\java\templates,or edit the custom build.xml by adding the following commands to the clean model target:

Example

Review a sample event handler that reformats currency amounts in recordset fields.

 

Related Topics
Bullet About event handlers
Bullet Event handler guidelines