From Wiki
There are potentially several ways to load reports with a subreport to JasperReports Server. The following recommendation is taken from Section 8.5.4 of the JasperReports Server Pro Ultimate Guide.
Create the Reports in iReport
- In iReport create the subreport; give it a descriptive name (e.g. “subreport.jrxml”).
- In iReport create the main report; give it a descriptive name (e.g. “mainreport.jrxml”).
- In iReport drag a Subreport component from the Palette into the main report’s Detail band.
- Follow the Subreport wizard:
- Use an existing report: Browse to locate the file you created in step 1 (e.g. “subreport.jrxml”).
- Use the same connection used to fill the master report
- (Parameters)
- Store the directory name in a parameter: $P{SUBREPORT_DIR} + “subreport.jasper”
- Finish
- Save the main report locally. Do not close the file; you want the main report open. You will use it in step 10.
Upload the Report Unit to JasperReports Server
- If it’s not already open, display the Repository Navigator: Window > JasperReports Server Repository.
- Browse through the Repository Navigator. Right-click the folder into which you want to upload the report unit.
- Click Add > Report Unit.
- Enter a descriptive Name and Description for the report unit (the report unit includes the main report, subreport(s), and any other resources).
- For the Main JRXML, click “Get source from current opened report”.
- For Locate Data Source you can select a datasource that’s already loaded into the JasperReports Server repository. If you don’t yet have a data source, you can click Locally Defined and follow the wizard.
- Click Finish. The JRXML validation box appears. Accept all its proposed changes.
JasperReports Server Converts the Subreport Expression
Result: the most significant change is that upon loading the report unit in step 12, JasperReports Server stores the subreport as a report resource and converts the Subreport Expression. For example the Subreport expression specified in step 4.4, above when the file was worked locally within iReport:
$P{SUBREPORT_DIR} + "subreport.jasper"
becomes
"repo:subreport.jrxml"
when uploaded as part of a report unit to the shared JasperReports Server repository.
Suggested Reading
To learn the basics of creating subreports, refer to http://jasperforge.org/website/ireportwebsite/IR%20Website/ir_subreports.html?header=project&target=ireport. More information is available in Chapter 11 of the iReport Ultimate Guide.
You can purchase the Jaspersoft Ultimate Guides at http://www.jaspersoft.com/ultimate-guides.