(For more resources on JasperReports, see here.)
You need a Java JAR file that contains class files for the JavaBeans required for this recipe. A custInvoices.jar file is contained in the source code (chap4). Unzip the source code file for this article and copy the Task5 folder from the unzipped source code to a location of your choice.
How to do it…
Let’s start using Java objects as data storage units.
- Open the ModelBeansReport.jrxml file from the Task5 folder of the source code for this article (chapt 4). The Designer tab of iReport shows a report containing data in the Title, Column Header, Customer Group Header1 and Detail 1 sections, as shown in the following screenshot:
- If you have not made any database connection so far in your iReport installation, you will see an Empty datasource shown selected in a drop-down list just below the main menu. Click on the Report Datasources icon, shown encircled to the right of the drop-down list in the following screenshot:
- A new window named Connections / Datasources will open, as shown next. This window lists an Empty data source as well as the datasources you have made so far.
- Click the New button at the top-right of the Connections / Datasources window. This will open a new Datasource selection window, as shown in the following screenshot:
- Select JavaBeans set datasource from the datasource types, as shown next. Click the Next button.
- A new window named JavaBeans set datasource will open, as shown in the following screenshot:
- Enter CustomerInvoicesJavaBeans as the name of your new connection in the text box beside the Name field, as shown in the following screenshot:
- Enter com.CustomerInvoicesFactory as the name of the factory class in the text box beside the Factory class field, as shown in the following screenshot:
This com.CustomerInvoicesFactory class provides iReport with access to JavaBeans that contain your data.
- Enter getBeanCollection as the name of the static method in the text box beside The static method… field, as shown in the following screenshot:
- Leave the rest of the fields at their default values. Click the Test button to test your new connection to the JavaBeans datasource. You will see an Exception message dialog.
- This exception message occurs because iReport can’t find your factory class. Dismiss the message box by clicking OK.
- Click the Save button at the bottom of the JavaBeans set datasource window and close the Connections / Datasources window as well.