Dynamically create jasper-reports subtask report

I am trying to create a report from java code with jasper messages (without iReport).

Successfully created the following elements:

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

The problem is, how can I refer to the subReportDesign object from subReportElement ?

So far, the only way I have found was to set the subReportElement "expression" in the $P{REPORT_PARAMETERS_MAP}.get("subreportobject") field and put subReport in reportDesign at compile time.

Is there another way? For example, is it possible to use variables - in some way ... - before compiling the main report?

thanks krisy

+4
source share
1 answer

If the subreport XML files are not in a known place, a report parameter map is the only way to do this. This requires temporary files from what I found, but that was a couple of years ago. I made a similar setup (JRXML is in the database). For each report, I had to do this before compiling the main 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); 
0
source

Source: https://habr.com/ru/post/1382881/


All Articles