1

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?

Antti
  • 43
  • 1
  • 7
  • If you go for subreports, will subreports have different designs or same design with different data? – Darshan Lila Oct 29 '14 at 05:49
  • some subreports have different designs and some have same designs with different content. – Antti Oct 30 '14 at 06:34
  • There will be no problem when you have same design subreport, but for different designs you need to create different subreports and hook them at runtime. – Darshan Lila Oct 30 '14 at 06:42
  • Simplest subreport has only one textfield, most have images and/or multiple textfields and one subreport has one table. User selects which "products" he/she wants to print and then I need to combine all "product" subreports into one. Currently I can create all "products" as JasperPrint objects and then I merge them to one JasperPrint. Unfortunately there will be too many pagebreaks because each JasperPrint starts from a new page and some "products" have only one row of text. – Antti Oct 30 '14 at 06:49
  • I don't mind creating several designs. I already have them. The problem is how to combine them in runtime... – Antti Oct 30 '14 at 06:51
  • I think you can use `printWhenExpression` on sureports, have all of subreports in one and based on `printWhenExpression` they can be chosen to either display or not. – Darshan Lila Oct 30 '14 at 06:53
  • Let me put it into a answer for better explanation. – Darshan Lila Oct 30 '14 at 06:54
  • Can you guys take a look at : https://stackoverflow.com/questions/53615452/dynamicjasper-how-to-add-a-subreport-as-columns – KenobiBastila Dec 04 '18 at 16:34

1 Answers1

2

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.

Darshan Lila
  • 5,772
  • 2
  • 24
  • 34
  • Thanks! I finally got it working. Subreport didn't show because I didn't send a JREmptyDataSource to it... Although, this sort of solution requires a lot of work which could be done in more generic way. Main problem is using one table jasper-file where table may have different columns. Can JasperReports have one Table which can be supplied data with different columns? – Antti Oct 30 '14 at 09:29
  • Care to give me a sample code or explanation how I modify .jasper -file's table component's columns at runtime? – Antti Nov 03 '14 at 06:31
  • The components and columns will be there all the time, just that it will be displayed based on ``. For instance if you have 5 columns and want to show first two, set `` for last three to false using a parameter that you'll pass to report. – Darshan Lila Nov 03 '14 at 09:48
  • Okay, thanks! This add all and then show only part of it sounds a bit hacky solution, but I guess I can live with that. – Antti Nov 05 '14 at 05:21