Often, report development involves repetitive tasks. Things such as report headers, commonly used datasets and data sources, formatting, and other elements are used in many different reports. This is where libraries come into play. When using libraries, report developers can store commonly used components for later reuse. It is also a useful tool when working in groups.
The concepts of reuse and group development are often overlooked in report development, and this seems to be all but entirely ignored with BIRT. However, if we have worked in a report development group, it is an all too often needed functionality. When I was working in a large report development group, the data that got pulled was often the same, if not similar, to previous report requests, with modification to visual layouts, or modified parameters. Another scenario that was common was to develop reports only to find out that someone had done the same report several months ago. With BIRT's report libraries, these kinds of common tasks can be stored in a central report library and made accessible to other developers to reuse and share their components. This is even useful in single developer situations to avoid having to rebuild commonly used objects in different reports.
In BIRT, libraries are similar in structure and design to a report document. The main difference being that libraries can be referenced inside of report designs and the visual editor for libraries will be different. When there are changes to library elements, these changes will trickle down into the report designs that are using them. The only exception is with chart elements in versions of BIRT prior to 2.2.
As with report designs, a library can be created using either the New option under the Navigator or the File menu. This is nice as it does not deviate from the expected behavior. In the following example, we are going to create a new Report Project called Classic Cars Library and create a new library using it.
Classic Cars With Library
. ClassicCarsLibrary.rptlibrary
.Now that we have a library, we need to add a few components to it. With the reports that we have created throughout the book, we have used a consistent data source, the Classic Cars Sample Database. This would make a good candidate for a library item.
In the following example, we will add a data source to a library.
ClassicCarsLibrary.rptlibrary
, if it is not already opened. dsClassicCars
. Click Next.Now we have a data source in a library. This was easy to do. Most of this should be familiar as it is the same steps to add to a report design.
In our reports, we will want to add in simple report headers containing a logo for the Classic Cars Company, a company title line, and a report title line. The report title line will be populated by a report parameter so that the design of the header is consistent, but the title will be dynamic.
hdrGrid
under the General tab of the Property Editor. Image
object from the Palette over to the single, large cell. hdrLogo
under the General tab of the Property Editor. hdrHeaderLabel1
under Properties. hdrHeaderLabel2
. Report Parameters/All/rprmReportTitle
as the data expression. The final expression should be params["rprmReportTitle"]
when done. Text
object over to the third row. Set the name to hdrHeaderLabel3
.<VALUE-OF>new Date()</VALUE-OF>
.The finished component will look like the following image:
We now have two components stored in a library—a report header and a data source. How do you consume them. Well, that's what we are going to look at next. Using elements in a library is fairly straightforward. We only need to use the library in a report design that is stored in a project, and we are ready to go. We will look at how to do this in the next example.
Classic Cars With Library
report. Call it CustomerOrderForm.rptDesign
. Use the blank report template.Take note of the icon in the report outline. The chain in the icon indicates that this report item is linked to a library. This is a different icon from a regular data source icon.
rprmReportTitle
to the report or simply right-click on rprmReportTitle
and choose Add To Report. hdrGrid
object. Select the Data Sources icon under the Outline tab. We will notice that the option to Add to Report is grayed out as the correct target location is not selected in the report design outline. This is one caveat to adding through context menus, which is not an issue with dragging and dropping. hdrGrids
in the libraries and choose Add to Report. rprmReportTitle
under Report Parameters, right-click, and choose Edit.In the previous example, we must have noticed that when we preview the report, date is incorrect. In fact, it is showing us the HTML markup, not an actual date, which isn't right. The problem is that any report that uses this report header will suffer from the same problem. Now, we could fix these in each of the reports themselves; however, the fix would be local to that report only. We would surely like this fix to trickle down to all reports that are using these items. In order for that to happen, we need to edit the library itself.
ClassicCarsLibrary
. hdrGrid
. It should become visible in the Report Design pane. hdrHeaderLabel3
in the third row, second column to open the Text Item Editor. ClassicCarsLibrary.rptlibrary
. CustomerOrdersForm.rptDesign
. We will be prompted that the library has been updated and we will be asked whether we want to reload the changes. Choose OK.It should be noted that once we change a component in a report such as its text, it then becomes a part of the report and not of the library. This is because technically the components consumed within a report become extensions of components in a library. When we change something, we are changing the extension, not the original; however, unmodified components will still reflect changes. The following example will demonstrate that changes made in the report will take precedence over the original library item.
hdrHeaderLine1
label in the Report Design file. ClassicCarsLibrary.rptlibrary.
<Value-Of>new Date()</Value-Of>
tag. Save the library.In the example that we just discussed, the change made in the report will take precedence over the change made in the library, while the deleted line will not be displayed in the report as the change will trickle down. It can be inferred from the following screenshot that the local change to the company title take precedence over the library changes, but the deleted date line shows in both.
So far in this chapter, we have looked at developing and publishing components into a report library from scratch. We then looked at how reports could consume those libraries and link in those components. Next, we looked at editing the libraries and having them trickle down to reports.
So, what happens when we have a report we have developed and there are portions we want to share with others; how do you go about publishing these components to libraries?
Fortunately, there is an easy way to do this. From the context menu, we can right-click on an element and add it to a library.
The next example will show us how to add report components from a report to a library. We will create a basic query to retrieve customer information, which we will use later to combine with a second dataset to have a master/detail type report.
getCustomerInformation
to the report.select * from CLASSICMODELS.CUSTOMERS where CLASSICMODELS.CUSTOMERS.CUSTOMERNUMBER = ?
rprmCustomerID
and link it to the dataset. Use the default value of 148 to make development a little easier so that we can debug and not have to enter a value each time. getCustomerInformation
. ClassicCarsLibrary.rptlibrary
as the location where we wish to export. rprmCustomerID
, located under the Report Parameters section of the Outline or Data Explorer.The problem with this method is that the dataset and the report parameter are both two separate instances from the report design files and the report libraries. The way to link them is to delete the instances in the report and consume them using the steps described earlier in this chapter.
getCustomerInformation
and rprmCustomerID
.