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:
- Navigate to the object in the model that relates to the behavior in the model that you want to extend or override.
- Use the New Event Handler dialog box to generate a basic template that includes the supported events for that handler type.
- 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.
- Rebuild the model JAR file. Once the class is in the model JAR 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.
- 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.
Example
Review a sample event handler that reformats currency amounts in recordset fields.