So far we've seen all of the JRDataSource
implementations provided by JasperReports. If we need to extract data from a type of datasource not directly supported by JasperReports, we can create a class implementing JRDataSource
to meet our needs. In this section, we will create a custom datasource allowing us to generate reports from an instance of java.util.List
containing arrays of strings as its elements.
In our previous examples, all JasperReports datasources implement the JRDataSource
interface. JasperReports also includes the net.sf.jasperreports.engine.JRRewindableDataSource
interface. This interface extends JRDatasource
, adding a single method called moveFirst()
. The moveFirst()
method is intended to move the cursor to the first element in the datasource. Our custom datasource will implement JRRewindableDataSource
. Let's take a look at the source of the custom datasource class.
package net.ensode.jasperbook; import java...