HOW-TO Add Concatenated Subreports

Concatenating many reports in a single one (eg: a single PDF) can be a hard task. Using DynamicJasper it is really easy get reports of different nature in a single one.

Useful examples:

Test Sample PDF
Creates a single PDF that concatenates 3 reports
DynamicReport dynamicReport = createSubreport1();

drb.addConcatenatedReport( dynamicReport, new ClassicLayoutManager(), "statistics",

params.put("statistics", getStatisticsList() );

dynamicReport: A DynamicReport object to use as a subreport. In this example we create it in the call to createHeaderSubreport()

LayOutManager: Since the subreport is going to be a DynamicReport, a LayOutManager is needed

path to the data source: A string that points to the data source.

origin of the data source: A constant from DJConstants class which can be: SUBREPORT_DATA_SOURCE_ORIGIN_FIELD or SUBREPORT_DATA_SOURCE_ORIGIN_PARAMETER, it just tells the subreport where to look for the data source (the parameters map, or if its a property of the current row)

For example, if path to the data source is “statistics” and origin of the data source is SUBREPORT_DATA_SOURCE_ORIGIN_PARAMETER, then it will look in the parameters map for an object under the key of “statistics”, on the other hand if we pass SUBREPORT_DATA_SOURCE_ORIGIN_FIELD, in the current row, there must be a property with the name “statistics” that returns an object of the type DATA_SOURCE_TYPE_<XXX>

type of the data source: A constant from DJConstants class, all types constants has a name like DATA_SOURCE_TYPE_<XXX>, where <XXX> represents the type. Most known types are java.sql.ResultSet, Collection, Array, Xml, etc.

There are other flavors for the concatenated reports, like passing an already compiled jasperReport object

Fork me on GitHub