How to pass parameters for the subreports in Ireport from Java Application?

Parameters passing to the sub report is difficult in many of the Business Intelligence tools. But in Ireport & Java we can do this in a simple manner.

Developers will often need to use different data source , multiple data source from the Main report in Subreport. This can be achieved by the following way.

From the application parameters can be passed to the jasper files at run time by using HashMap. Even the data source can also be sent(ie Resultsets.)

Now the main report has the datasource parameter. Now this has to be used(linked) for subreport.

1. From Subreport Element Right click the Properties

2.In the Sub Report select “Use data source expression” then select the name of the parameter containing the result source for the supreport. Ex $P {My_Subreport_datasource}
3.Note : The data type of the parameter is to be from one of the Data source Datatype (ex new JRResultSetDataSource , JRBeanCollectionDataSource etc..) . This datasource can be added in the combo box . By default it won't be available in the Parameter Class Type.
4.When Master reports are filled with JasperFillManager.fillReport method the sub report parameters also has to be filled.

No comments:

Post a Comment

Page copy protected against web site content infringement by Copyscape