Subreports in Jasper Reports
Subreport is an advanced feature of Jasper Reports and is used to design complex reports. Subreport is a report inside another report. The datasource connection used by the Subreport is same as the parent report.
From the iReport Designer palette, we can select the subreport element and drop it in the master report to create a subreport. Now a subreport wizard opens which gives the option to create a new report or modify existing report. Here, we can define the data source connection also. Once the subreport is created, we can add fields to the subreport as in a normal report.
Now, the subreport element is added in the main report.
Now, select the properties of the subreport and set the 'Connection type' as 'Use a DataSource Expression' and 'Data Source Expression' as '$P{SR_DATA_SOURCE}' (any name as you wish) with the parameter class as java.lang.Object. With these parameters set, we can create a subreport inside a master report.