Understanding the event handler execution sequence
This section explains the order of execution of the BIRT event handlers.
About event firing sequence dependency
The event firing sequence for ReportItem and ReportDesign events depends on whether the report is run in the BIRT Report Designer previewer or elsewhere, such as in the Web Viewer. When a report runs outside the previewer, the generation phase always completes before the presentation phase begins. When a report runs in the previewer, the generation and presentation phases are not distinctly separated. The onCreate event is a generation-time event and the onRender is a presentation-time event.
About the onCreate and onRender firing sequence dependencies
When a report runs in the BIRT Report Designer previewer, all ReportItem onRender events fire immediately after their corresponding onCreate events. When a report runs outside the previewer, all onCreate events fire as a part of the generation process, while the onRender events fire as a part of the presentation process.
About the ReportDesign firing sequence dependencies
When a report runs in the previewer, the ReportDesign initialize event fires only once, and is always the first event fired. When a report runs outside the previewer, the initialize event is fired twice, once at the beginning of the generation phase and once at the beginning of the presentation phase.
The ReportDesign beforeRender and afterRender events also fire at different times, depending on whether the report runs in the previewer. When a report runs in the previewer, beforeRender fires once near the start of the report, just after beforeFactory fires. The ReportDesign afterRender event fires once, near the completion of the report, just before the afterFactory event fires.
When the report runs outside the previewer, the ReportDesign beforeRender event fires once, immediately after the firing of the initialize event in the presentation phase. When the report runs outside the previewer, the ReportDesign afterRender event is the last event fired.
About the pageBreak event
Table and Text objects have event handlers for handling page break events. The pageBreak event is fired in the presentation phase whenever a page break occurs.
Analysis of the execution sequence phases
The following diagrams present a more detailed view of the event handler execution sequence. The diagrams reflect the processing sequence when a report is run inside the previewer. When the presentation phase is separate from the generation phase, as it is when a report is run outside the previewer, an additional rendering sequence occurs. The rendering sequence is identical to the generation sequence with the following exceptions:
- There are no onPrepare events.
- There are no onCreate events.
- There are no data source or data set events because data is retrieved from the report document rather than the database.
- There are no beforeFactory and afterFactory events.
Overview of the report execution process
Figure 8-1 shows an overview of the report execution process. Each box in the diagram refers to another diagram that appears later in the chapter.
Figure 8-1 Method execution phases
The preparation phase includes initialization and master page creation, followed by opening the data source. The preparation phase is identical for all reports. Figure 8-2 illustrates the method execution sequence for the preparation phase.
Figure 8-2 Preparation phase
In Figure 8-2, the master page processing sequence depends on the structure of the report. A master page typically consists of one or more header and footer grids with rows, their cells, and the cell contents. The execution sequence for a master page parallels that for creating an ungrouped table, except that the master page contains no detail rows.
Report body processing phase
BIRT processes a report body by processing all the report items that are not contained in other report items. BIRT processes the items, going from left to right and proceeding a row at a time toward the bottom right. A report item that is not contained in another report item is called a top-level report item. Every report has at least one top-level report item, usually a grid, a list, or a table. If a report has more than one top-level report item, BIRT processes the top-level items in order, from left to right and top to bottom.
For each top-level item, BIRT processes all the second-level items before proceeding to the next top-level item. A second-level report item is a report item that is contained within a top-level item. For example, a table contained in a grid is a second-level report item.
There can be any number of levels of report items. To see the level of a particular report item, examine the structure of the report design in Outline, as shown in Figure 8-3.
Figure 8-3 The Outline window, showing the level of a report item
BIRT processes all items at all levels in an iterative fashion, following the same process at each level as it does for the top-level items.
Figure 8-4 illustrates the general report body processing phase.
Figure 8-4 Report body processing phase
Clean-up processing phase
The clean-up phase consists of two methods that execute upon closing the data source, followed by a final method that executes after the generation phase. Figure 8-5 illustrates the method execution sequence for the clean-up phase.
Figure 8-5 Clean-up phase
Row execution sequence
There are three kinds of rows: header, detail, and footer. Tables, lists, and groups have rows. BIRT processes all rows identically. Figure 8-6 illustrates the method execution sequence for a row.
Figure 8-6 Row execution sequence
Table and list method execution sequence
A list is the same as a table, except it only has a single cell in every row. BIRT processes tables and lists identically except that for a list, BIRT does not iterate through multiple cells. BIRT processes tables in three phases, the setup phase, the detail processing phase, and the wrap-up processing phase, as shown in Figure 8-7.
Figure 8-7 Table and list execution sequence
The following sections describe each of the three table and list execution sequence sections.
Table and list setup phase
The pre-table processing phase is the same for all tables, both grouped and ungrouped.
Figure 8-8 illustrates the method execution sequence for the pre-table processing phase.
Figure 8-8 Table and list setup execution sequence
Table and list processing phase
The sequence for the table and list processing phase depends on whether the table or list is grouped. The diagram for an ungrouped table or list is shown in "Ungrouped table or list detail execution sequence," later in this chapter. The diagram for a grouped table or list is shown in "Grouped table or list execution sequence," later in this chapter.
Table and list wrap-up phase
The post-table processing phase is the same for all tables, both grouped and ungrouped. Figure 8-9 illustrates the method execution sequence for the post-table processing phase.
Figure 8-9 Table and list wrap-up execution sequence
Ungrouped table or list detail execution sequence
A table or list with no grouping has a different sequence than one with grouping.
Figure 8-10 illustrates the execution sequence for a table or list without grouping.
Figure 8-10 Ungrouped table or list detail execution sequence
Grouped table or list execution sequence
One of the differences between the processing sequence for a table or list with grouping and a table or list without grouping is that for a table with grouping, BIRT creates one ListingGroup item per group.
The ListingGroup element has three methods, onCreate, onRow, and onFinish, all of which are called one or more times when processing a grouped table or list. A ListingGroup is very similar to a table because it has one or more header rows, one or more detail rows, and one or more footer rows. BIRT processes grouping rows in the same way that it processes a table row.
Figure 8-11 illustrates the method execution sequence for a table that has groups.
Figure 8-11 Grouped table execution sequence