BIRT event types
BIRT supports the following types of events:
*Parameter
*Report design
*Data source and data set
*Report item
Each event type has a series of events that fire during report processing.
Parameter events
BIRT currently supports two parameter level events that can be used to customize the parameter selection choices and default values before the parameter entry box is displayed. In addition, BIRT supports one parameter level event that is called after the parameters have been selected. These events are summarized in Table 36-1. These events are currently available only in JavaScript. Parameter events fire only if the report contains parameters.
Table 36-1 Parameter events
Event
Description
getDefaultValueList
Sets the parameter’s default value. If the parameter is set to allow multiple values, this script should return an array of values that will then be pre‑selected in the parameter entry box. This event fires first.
getSelectionValueList
Returns a single value or an array of values. For parameters presenting a list of values, this event fires before the parameter entry box displays. Simple text parameters do not call this event.
validate
This event fires after the user selects the report parameters and before the initialize event. This event fires for each parameter and returns a value of true or false. Returning false throws an exception that states which parameter failed validation. Returning true processes the report normally.
Listing 36‑1 provides an example of event handlers, getDefaultValueList and getSelectionValueList, for a parameter formatted as a list box. The dSLArray array contains four values that a report user can select. The array dVLArray contains two values that are the default values of the parameter. These values are selected in the list of available values when the user runs the report.
Listing 36‑1 Example event handlers for a parameter formatted as a list box
//getDefaultValueList
var dVLArray = ["10104","10108"];
dVLArray;
 
//getSelectionValueList
var dSLArray = ["10101","10104","10105","10108"];
dSLArray;
The getDefaultValueList can be useful to provide date parameters as well. If changes to the parameter are necessary after a user enters a parameter or if extra parameter validation is required, write an event handler for the validate event. The following example shows a validate script for a string parameter:
params["MyParameter"].value = "Something Else";
true;
Report design events
Report design events fire for all reports. Table 36-2 describes these events. The events support event handlers to provide additional processing of the report.
Table 36-2 Report design events
Event
Description
initialize
Fires every time a task accesses the report design (.rptdesign) or the report document (.rptdocument). This event occurs once when using RunAndRenderTask. When the processing phases run separately, RunTask triggers initialize( ) once for the generation phase and RenderTask triggers initialize( ) once for every render operation. Using the page navigation controls to access a new page in the presentation phase also triggers this event handler.
beforeFactory
Fires just prior to the generation phase after the elements in the report have been prepared in the preparation phase. This event handler fires only once. Use beforeFactory( ) when modifications to the report design are required before execution.
beforeRender
Fires just prior to the presentation phase and is called for every render operation. In the RunAndRender task, this event occurs once just after the beforeFactory event.
afterFactory
Fires at the conclusion of the generation phase and fires only once. If using a RunTask or RunAndRenderTask, this event is the last one fired. If using a RenderTask, this event does not execute.
afterRender
Fires at the conclusion of the presentation phase for a specific render operation. If using a single RunAndRenderTask process, this event is called only once. If using separate RunTask and RenderTask processes, this event fires for every render operation.
onPageStart
Fires prior to placing content on a specific page and supports the use of page‑level variables to modify the page. This event fires only when processing phases run separately, for example, a RunTask followed by a RenderTask. This event fires prior to the onPageBreak events for the individual elements to be placed on the page. This event is also available on the master page.
onPageEnd
Fires after all the onPageBreak events have fired for the content to be placed on a page and prior to evaluating the autotext items for the page. This event is also available on the master page.
Types of data source and data set events
There are several kinds of data sources and data sets. A data source can be a flat file, a JDBC data source, a scripted data source, a web services data source, or an XML data source. All data sources have a common set of event handlers. A scripted data source has two additional event handlers.
Data set events can be called multiple times to support multipass aggregation and data set sharing. It is not advisable to write event handlers that rely on the data set event firing order. An additional issue is that data set event handlers may only be called once because of data set caching. Table 36-3 describes the data source events.
Table 36-3 Data source events
Event
Description
beforeOpen
This event is most often used to modify public properties of the data source, including database URL, username, password, driver class and JNDI URL. This event fires only once, before the connection to the data source opens event, when the connection uses multiple data sets. Fires prior to opening a connection to a data source.
afterOpen
Fires after the connection to the data source opens.
beforeClose
Fires at the conclusion of the generation phase, just prior to closing the data source connection.
afterClose
Fires after the data source connection closes.
open
Fires only for a scripted data source, providing a location for the developer to set up a connection to an external source.
close
Fires only for a scripted data source, providing a location for the developer to close a connection to an external source.
Data source and data set events fire in the generation phase prior to the onCreate event of the report item that uses them. Data set events can fire several times. The event order is covered in more detail later in this chapter. Table 36‑4 describes the data set events.
Table 36‑4 Data set events
Event
Description
beforeOpen
Fires prior to opening a data set and used most often to modify public properties of the data set. For example, when using a JDBC data set, the query text can be altered using this event. This event fires for every report item bound to the data set. If two tables use the same data set, the data set is called twice, resulting in this event firing twice. Since version 2.6, BIRT allows report items to be bound to other report items, in which case the data set is called only once, resulting in the event triggering only once. Data set caching options continue to be added which affect how often data source and data set events fire.
afterOpen
Fires after the data set opens.
onFetch
Fires as the data set retrieves each row of data. This event fires for all rows of data before the onCreate event for the particular report item that uses the data set.
beforeClose
Fires before closing the data set after creating the report item that uses the data set.
afterClose
Fires after the data set closes.
open
Fires for a scripted data set, providing a location for the developer to set up a data set.
fetch
Fires for a scripted data set, providing a location for the developer to populate rows from the scripted data set.
close
Fires for a scripted data set, providing a location for the developer to close the set.
Data source and data set events fire prior to being used on a data bound item. If the data set is never used in the report, the data source and data set are never called. A scripted data set is a data set that accesses a scripted data source. A non‑scripted data set is one that accesses a standard data source. Use the scripted data source and data set to write custom code to retrieve data values.
Scripted data source events
A scripted data source contains the afterOpen, afterClose, beforeOpen, and beforeClose events common to all data sources, and open and close events. Use the event handlers for the open and close events to perform the actions of opening and closing the data source.
Scripted data set events
A scripted data set contains the afterOpen, afterClose, OnFetch, beforeOpen, beforeClose, open, close, and fetch events. Use the event handlers for the open and close events to perform the actions of opening and closing the data set. Use the fetch method to fetch a row from the data source. Using a scripted data set requires an event handler to be written for the fetch event.
ReportItem events
ReportItem events trigger for report items that are placed in the report. Most items support writing event handlers for the events listed in Table 36-5.
Table 36-5 Report item events
Event
Description
onPrepare
Fires at the beginning of the preparation phase before data binding or expression evaluation occurs. This event is useful for changing the design of the item prior to generating the item instance.
onCreate
Fires at the time the generation phase creates the element. This event is useful when a particular instance of a report item needs alteration.
onRender
Fires in the presentation phase. This event is useful for operations that depend on the type or format of the output document.
onPageBreak
Fires for all report items currently on the page when the page break occurs. Not all report items support the onPageBreak event.