4
votes

I'm trying to generate a report from java code with jasper-reports (without iReport).

Have successfully created the following elements:

  • Master report object (class: JasperDesign) named reportDesign
  • Sub report object (class: JasperDesign) named subReportDesign
  • SubReport element (class: JRDesignSubreport) in the Master report named subReportElement
  • Compiled Sub report (class: JasperDesign) named subReport

The problem is, how do I reference the subReportDesign object from the subReportElement?

So far the only way I found, was to set subReportElement's "expression" field to $P{REPORT_PARAMETERS_MAP}.get("subreportobject"), and to put subReport into reportDesign during the compilation.

Is there another way? For example can I use variables - in some way .. - before compiling the Master report?

thanks, krisy

1
I would like to know, is filling the report_parameters_map is the only way, to use subreports (besides writing the jrxml file onto the HDD)?krisy

1 Answers

1
votes

If the subreport XML files are not in a known location, the report parameters map is the only way to do it. It does require temp files from what I found, but this was a couple of years ago. I've made a similar set up (JRXML is in a database). For each subreport I had to do this prior to compiling the master report:

 byte[] bytes = subreportXMLString.getBytes("UTF-8");
 InputStream input = new ByteArrayInputStream(bytes);

 File compiledReportFile = File.createTempFile(subreportParameterName, ".jasper");
 FileOutputStream buffer = new FileOutputStream(compiledReportFile);
 JasperCompileManager.compileReportToStream(input, buffer);
 input.close();
 buffer.close();
 reportParameters.put(subreportParameterName, compiledReportFile);