2 min read

(For more resources on JasperReports, see here.)

Getting ready

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.

  1. 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:

    JasperReports 3.6

  2. 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:

    JasperReports 3.6

  3. 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.

    JasperReports 3.6

  4. 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:

    JasperReports 3.6

  5. Select JavaBeans set datasource from the datasource types, as shown next. Click the Next button.

  6. A new window named JavaBeans set datasource will open, as shown in the following screenshot:

    JasperReports 3.6

  7. Enter CustomerInvoicesJavaBeans as the name of your new connection in the text box beside the Name field, as shown in the following screenshot:

    JasperReports 3.6

  8. 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:

    JasperReports 3.6

    This com.CustomerInvoicesFactory class provides iReport with access to JavaBeans that contain your data.

  9. Enter getBeanCollection as the name of the static method in the text box beside The static method… field, as shown in the following screenshot:

    JasperReports 3.6

  10. 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.
  11. This exception message occurs because iReport can’t find your factory class. Dismiss the message box by clicking OK.
  12. Click the Save button at the bottom of the JavaBeans set datasource window and close the Connections / Datasources window as well.

LEAVE A REPLY

Please enter your comment!
Please enter your name here