Subreports are great for many purposes. They are a great way to add data coming from a different datasource or to centralize a piece of a report that is the same in many reports. With subreports you don't need to repeat yourself or do copy/pastes; all you need to do is modify only one subreport instead of many master reports.
Environment
This has been verified and tested using iReport 4.0 and higher
The issue
What I've found is that when I use xml datasource, the data in the subreport doesn't appear. So I have my subreport using my XML datasource with a Xpath query and when I run it, my chart and table are displayed correctly, but when I include it in a master report and set the subreport to use the main datasource then no data appears.
The solution
Because of the nature of the datasource, the datasource isn't passed to the subreport in the usual way. When using an xml datasource you will notice that there are additional default parameters. One of them is XML_DATA_DOCUMENT.
- To make sure your data are passed to the subreport you need to go to the properties of the subreport and scrolling down to the bottom, you will find the Parameters property.
Open it using the ellipsis button () and add a new link to pass a parameter to your subreport. In the Subreport parameter name field you need to enter XML_DATA_DOCUMENT and in the Value expression field pick $P{XML_DATA_DOCUMENT}.
- Press OK twice
- In the sub-report properties you can also find the property Connection type
Select Don't pass data in the Connection type.
This way the subreport will have access of the xml datasource and should display its content the same way as it does running on its own separatly using that XML datasource.
Recommended Comments
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now