Example: Attaching and Testing an Event Handler

The example below attaches and tests a sample event handler for reformatting currency amounts in recordset fields. Before you begin, you should review the basic steps for creating an event handler.

This example uses two Java files:

Follow these steps the implement the currency formatting event handler:

  1. Open the CCSDemo model and press Return to connect.


  2. Create a folder named fieldformatting under <vhi>\models\CCSDemo\scripts\src\.


  3. Copy CurrencyFormatter.java and CurrencyFieldHandler.java to the folder you just created.


  4. On the Events menu in the Design Tool, click Rebuild. The Build Output window indicates when the build is complete.


  5. In the Entity window, select the AcctTransactions entity.


  6. Click the Recordset tab, and then click the Fields subtab.


  7. Select the Amount Field, then click the Advanced Properties button.


  8. In the Advanced Recordset Field Properties dialog box, select fieldformatting.CurrencyFieldHandler from the Event Handler list.

    This dialog box also has options for reviewing the properties of the event handler or inspecting the code in your default Java editor.


  9. Click Close to attach the event handler to the Amount Field. When you return to the Fields tab, the Amount field now has a lightning bolt displayed to the left, indicating that an event handler has been attached.


  10. Click Apply to activate your changes.


  11. To test the event handler, select Recordset Test from the Debug menu. Confirm that AcctTransData is listed as the Recordset and Fetch Records is listed as the Action.


  12. Click Execute. After the test is complete, the returned values in the Amount column have a dollar sign and negative amounts are surrounded by parentheses, as they will be when returned to a client application.