Project Wiki
Views

Uploading Report Units with Subreports

From Wiki

Jump to: navigation, search

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.

Contents

Create the Reports in iReport

  1. In iReport create the subreport; give it a descriptive name (e.g. “subreport.jrxml”).
  2. In iReport create the main report; give it a descriptive name (e.g. “mainreport.jrxml”).
  3. In iReport drag a Subreport component from the Palette into the main report’s Detail band.
  4. Follow the Subreport wizard:
    1. Use an existing report: Browse to locate the file you created in step 1 (e.g. “subreport.jrxml”).
    2. Use the same connection used to fill the master report
    3. (Parameters)
    4. Store the directory name in a parameter: $P{SUBREPORT_DIR} + “subreport.jasper”
    5. Finish
  5. 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

  1. If it’s not already open, display the Repository Navigator: Window > JasperReports Server Repository.
  2. Browse through the Repository Navigator. Right-click the folder into which you want to upload the report unit.
  3. Click Add > Report Unit.
  4. Enter a descriptive Name and Description for the report unit (the report unit includes the main report, subreport(s), and any other resources).
  5. For the Main JRXML, click “Get source from current opened report”.
  6. 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.
  7. 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.