Nested subreport within iReport & JasperReports Server

iReport, JasperReports Server & subreports what a nightmare

It has taken far too long to work out how to get them to play nicely, so I thought I’d sum it up since I couldn’t find any complete information on how to do it.

There is partial information which I based the following on here

  • Connect iReports to JasperReports Server, so you can add content.
  • In the ‘Repository Navigator’ Right click on your server name and select ‘Add’ / ‘Folder’.
  • Right click on the new folder and select ‘Add’ / ‘JasperServer Report’.
  • Enter an ID, Name & Description for your report, the ID needs underscores instead of spaces.
  • Locate the main JRXML file, I’ve select one from my HDD.
  • Locate the Data Source, I’ve select one that I’ve already created on the server, its easy to create.
  • On clicking finish, a dialog box ‘JRXML validation’ might pop up, this is iReports checking your main report for any subreports, it then changes any subreports links in order to reference the file in the repository. Click continue to whatever it suggests.
  • Note this above part has changed your master file to point to “repo:subreport.jrxml” rather than what it referenced before, which was “subreport.jasper”.
  • Now if you open out your tree you’ll notice that you’ve got a ‘Main jrxml’ and your subreport in your ‘Resources’ folder.
  • If you’ve multiple nested subreports, now is the time to upload them as well, because iReports has choosen to ignore any but the first one that it found.
  • Its easier to do this on the JasperReports Server side of things, find the new report in your Repository right click and ‘Edit’ it, then click ‘Controls & Resources’ / ‘Add Resource’ now upload another ‘subreport.jrxml’ file, Click ‘Next’ and give it a Name & ID, Click ‘Next’ & ‘Submit’.
  • Repeat above for any other subreports.
  • Switch back to iReports and Refresh your ‘Repository Navigator’ tree, in order to show the files uploaded in JasperReports Server.
  • In the ‘resources’ folder right click the subreport which is referenced first in the main jrxml file & click ‘properties’.
  • Hightlight and Copy with Ctrl + C the ‘Parent Folder’ line which displays, then click ‘Cancel’. In my case I’m copying the line /XX/Report1/Report1_files/Report1-Tenure.jrxml
  • Once copied, Right click & ‘Open in editor’ on the ‘Main jrxml’ report in your tree.
  • Highlight the subreport on the main report and click on the three dots next to the ‘Subreport Expression’ property in the properties panel.
  • Replace everything after “repo: with what is copied to your clipboard. in my case I end up with “repo:/XX/Report1/Report1_files/Report1-Tenure.jrxml”.
  • Click Save icon, and Right click on the Main report and write the changes back to it by selecting ‘Replace with current document’.
  • Link up your other Nested subreports in the same fashion, loading each one in turn to the editor, changing their ‘Subreport Expression’ property and write the information back to the correct resources jrxml file.
  • Making sure that you add “repo: before the path, as that wont be there as the nested subreport wasnt found by iReports first time around.
  • Now finally you can Right click the main report and ‘Run JasperServer Report’. Your report will also work on your server.
  • Other things to note, remove any refernces to ‘$P{SUBREPORT_DIR} +’ and just reference the actual subreport, otherwise it wont be able to find the file.

3 comments

  1. john

    I can say that the situation with report studio is significantly works than with ireport. ireport at least had a go, and would change the sub report definitions to repo:xxx.jrmxl. report studio does not even do that. When you manually do it, report studio does not then recognize any of the sub reports, so you can no longer run it in studio, and when you publish a report to the server, it no longer recognizes or publishes any sub reports. Doing it manually, as resources, does not work either – it can never find the sub reports.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s