Java Reference
In-Depth Information
This example is very similar to the previous example. The only difference is that we
use a
Collection
of
Map
objects instead of an array, and pass that to the constructor
of
JRMapCollectionDataSource
so that the
Map
objects can be used to populate the
report. It is worth noting that, even though we use
java.util.ArrayList
to group
the
Map
objects, this does not have to be the case. Any class implementing the
java.
util.Collection
interface will work just as well.
Java Objects as Datasources
In addition to databases and maps, JasperReports allows us to use
Plain Old Java
Objects (POJOs)
as datasources. We can use any Java object that adheres to the
JavaBeans specification as a datasource. The only requirements for an object to
adhere to the JavaBeans specification are that it must have no public properties, it
must have a no-argument constructor, and it must provide
getter
and
setter
methods
to access its private and protected properties. Let us create a Java object that can be
used as a datasource for our next example:
package net.ensode.jasperbook;
public class AircraftData
{
public AircraftData(String tail, String serial, String model,
String engine)
{
setTailNum(tail);
setAircraftSerial(serial);
setAircraftModel(model);
setEngineModel(engine);
}
public AircraftData()
{
}
private String tailNum;
private String aircraftSerial;
private String aircraftModel;
private String engineModel;
public String getAircraftModel()
{
return aircraftModel;
}
public void setAircraftModel(String aircraftModel)