Antti
Antti

Reputation: 43

Adding subreports to master report at runtime (java)

Alright, I couldn't find an answer to my question with google so...

Currently I'm using JasperReports and DynamicJasper to build my reports and print them. All works fine when I use just single jasper-files or jrxml-files. I also have a piece of code which merges all JasperPrint-files into one if I need to combine reports. However, this isn't really optimal...

Can I use one .jasper or .jrxml-file as a master report (it has a header, a footer and en empty detail-band) and fill its detail-band with 1-n subreports (currently in .jasper or .jxrml)?

Currently only one of my wannabe subreports use datasource (tablemodel) and other wannabe subreports get their data from parameters.

I've found several different ways to do something which could end up it a result which I want, but so far no success... Which builders/managers/whatever I need? Getting a bit frustrated because can't find enough info about different classes, methods and their parameters. Why they are there and what is required. Examples don't explain enough...

Should I use DynamicReportBuilder to build DynamicReport for the DynamicJasperHelper which generates JasperReport which in turn is filled with JasperFillManager.fillReport method?

Upvotes: 1

Views: 2152

Answers (1)

Darshan Lila
Darshan Lila

Reputation: 5868

Have all sub reports in one main report and use print when expression for visibility. Say following is the subreport code.

<subreport>
   <reportElement uuid="9f36c3cb-7e29-4040-a14e-6a91775e89e4" x="0" y="35" width="555" height="47">
      <printWhenExpression><![CDATA[$P{disp} == 1]]></printWhenExpression>
   </reportElement>
<!-- Other Element -->
</subreport>

Look out for following line in above code.

<printWhenExpression><![CDATA[$P{disp} == 1]]></printWhenExpression>

This means whole of sub report should be included on when $P{disp}.intValue() == 1. Here $P{disp}, is the parameter you would have to pass to report in order to work with printWhenExpression.

Parameters or not necessary, you can use a field as well. And conditions are based on you requirement.

Note : You can have simillar approach for all subreports.

Upvotes: 2

Related Questions