Handling Data Events

You can perform event handling in either of the following ways:

Synchronous data event handling

Synchronous data event handling occurs if DataDirector does not return from a data manipulation operation until it has the DataAccess object with the new data. In a Java-client application, during the time that the operation is in progress, the user interface of the presentation bean is frozen, that is, it does not repaint. In an HTML-client application, the user interface does not freeze.

For example, synchronous data event handling occurs if a BI Crosstab bean requests a drill and DataDirector does not return until the drill operation is completed. Completing the drill includes the fetching of data and the firing of the DataChanged event, which passes a refreshed DataAccess object with the data for the drill to the presentation bean. Synchronous data event handling is usually acceptable if the drilling operation requires only a small period of time such as a few seconds.

Note: In an HTML-client application, presentation beans should not be rendered (that is, written to HTML) if there is an outstanding data operation regardless of whether the processing is synchronous or asynchronous. While a long request is outstanding in an HTML-client application, a processing page can be displayed and it can poll the servlet to determine when the data operation is finished. A thin presentation bean can be rendered only after the data operation is finished.

Asynchronous data event handling

Asynchronous data event handling occurs when DataDirector returns from a data manipulation operation before it has the DataAccess object with the new data. As soon as DataDirector returns, then the presentation bean's GUI is able to repaint.

One way that asynchronous data handling can be accomplished is the use of multiple instances of DataAccess objects for a presentation bean. In this case, one instance of DataAccess holds the current data for the presentation bean and another instance can be created to pass data to the presentation bean after data was fetched for a query such as a drill operation.

To accomplish asynchronous data event handling, the implementation of DataDirector spawns a new thread to fetch the data that is needed for the drill and, while the new thread is performing its task, makes a satisfactory return to the presentation bean regarding the request to perform a drill. During this time, the presentation bean GUI does not freeze and the old instance of DataAccess should still be available although there is no longer a guarantee that data other than what appears on the screen is valid.

If you anticipate that the drill operation will require a longer time than the end user is willing to wait, then the implementation of DataDirector can display a progress bar and a Cancel button while the new thread is running. As soon as the new thread finishes its data operation, DataDirector fires the DataChanged event and thereby passes a reference to a new instance of DataAccess that contains the data for the drill. At that time, the presentation bean must replace the original instance of the DataAccess object by the new instance of the DataAccess object.

Interaction Between Presentation Beans, DataDirector, and DataAccess