Directory Discourse
Setting up the subreport is not trivial using Jasper Reports. There are at least two ways to tell a master report where to find sub-reports.
- Provide a value for the
SUBREPORT_DIR
parameter.
- Place the subreports within the CLASSPATH.
For solution 1, determine the absolute directory of the master report location at run time. Then, place subreports in relative directories under the master report. Finally, tell the master report the absolute path to the subdirectory containing the subreports.
I have not used solution 2.
Parameterized Master
Consider parameterizing the master report, instead of creating subreports.
- Add a list of parameters to the report.
- Drag the parameters onto the report header.
If you only have one report, but want to use a different logo (and company name, styling, and so forth), then use parameters to configure the look and feel.
Subreport Usage
I find it useful to create subreports when the queries for the data are nearly the same, but need to group the data in slightly different ways. The master report contains everything that is common (showing input parameters -- so that the report can be recreated, headings, company name, user name, time stamp, page number, and so on), and the subreports focus on the differences. Often, the subreports will overlap and only be executed depending on the value of an input parameter.