Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JasperReports: How to pass parameter to subReport

How to pass parameter to sub report in JasperReports?

I'm able to pass the parameter to master report but I'm not able pass parameter to its sub report.

Can any one give me the solution for it?

like image 830
reply2vivekshah Avatar asked Feb 22 '10 10:02

reply2vivekshah


People also ask

How do you pass a parameter to a subreport?

To specify parameters to pass to a subreport In Design view, right-click the subreport and then click Subreport Properties. In the Subreport Properties dialog box, click Parameters. Click Add. A new row is added to the parameter grid.

How do you pass a field to subreport in Jasper report?

Create a subreport parameter (for the sub-report from the main report) called "paramA" and pass it the value you wish by setting the report expression as needed. If the value is in a field try using $F{myField} as the expression, if its a parameter that was passed to the main report, use $P{myParam} etc.

How do you pass main report data source to subreport JasperReports?

With a SQL connection, you can just pass a Connection Expression like $P{REPORT_CONNECTION} . Then the subreport has its own SQL query. In your case you want to pass the actual data. Depending on the details, it might be as simple as just defining a Parameter Map Expression like $P{REPORT_PARAMETERS_MAP} .


1 Answers

Try using iReport if you are not.

When viewing a report within iReport you can select the properties of the subreport within the main report.

In this there is an option in Subreport properties called Parameters. Using this you can pass parameters to your subreport.

  • Select this and click the Add button.

  • Then click the button right of the Value expression Box

  • Next an option screen will pop up where you can select the parameter from the master report you want to pass.

If you want to do it via xml here's a quick example.

<subreport>
    <subreportParameter name="XML_ID">
        <subreportParameterExpression>
            <![CDATA[$P{MASTER_REPORT_PARAMETER}]]></subreportParameterExpression>
    </subreportParameter>
</subreport>
like image 51
Gordon Avatar answered Sep 21 '22 08:09

Gordon