AttributeFormatting Example

Purpose

This example shows how simple entity attributes, in this case those representing dates and currency values, can be reformatted for client applications. The event handlers use the defaultReadAttribute method on the AttributeEvent interface to read the underlying attribute. Currency and date attribute values from the host application are reformatted and returned as the attribute values used by the client.

The implementation of the example illustrates several points.

  1. A single handler class can be used with any number of objects within a model. Both the currency and date event handlers can be used with any attributes which require formatting in the way provided by a particular event handler.
  2. All of the processing performed by an event handler does not need to be written inline. Both the date and currency handlers use external shared classes (which are reused in the FieldEvents examples) to do the bulk of the work. This simplifies the actual event handler code, and promotes code reuse.
  3. The DateAttributeHandler class uses a read-only instance of a DateFormatter class to do the actual date parsing and conversion. A single date formatter is created as part of the class loading process, and is shared among all host sessions.

Model Design

The model used is an adaptation of the CCSDemo model. The date and currency values on the AcctProfile entity have had event handlers attached to them.

Execution

The event handlers can be called in the Design Tool by using the Debug Procedure Test menu command. Execute the Accounts.GetAccount procedure using the account number 167439459. The date and currency procedure outputs will display the results produced by the event handlers.

The event handlers can be called in the Server by deploying the model to the Session Server. Use the Web Builder to generate a procedure-based web application. Then execute the GetAccount procedure with an account number of 167439459. The date and currency outputs are generated by the event handlers.

CompoundAttribute Example

Purpose

This example illustrates how an event handler can be used to synthesize a single attribute (as seen by the client application) from several entity attributes (as displayed by the host application and as defined in the model). In this case the example shows how three separate date fields, a month, a year, and a day, are combined into a single date string, both for input and output.

The transformation required is simple enough that the conversion is simply done inline in the event handler itself.

Model Design

The model is a modified version of the CICSAccts sample model. The DayIssued, MonthIssued, and YearIssued attributes on the RecordDisplay entity have had the suffix _HIDE applied to them so that they will not be displayed in a Web Builder application. A single new attribute, DateIssued, has an event handler attached which will combine the three date attributes when a client application reads the attribute, and will write to the three date attributes when a client application writes to the attribute.

Execution

The event handler can be called in the Design Tool by using the Debug Procedure Test menu command. Execute the Accounts.GetAccount procedure using the account number 20000. The CompoundDate procedure output will display the composite date produced by the event handler.

The event handler can be called in the Server by deploying the model to the Session Server.