Mr. MonoChrome
Mr. MonoChrome

Reputation: 1383

Linking report parameters with subdataset parameters in Jasper Reports

I've looked at many write ups, and articles, but many of it seem old or are hard to read.

I created a report with a bunch of sub-Parameters. i saved that, created a bunch of input controls with the same name, and saved that to the jasper server. So by now i know its not that simple, i know you have to create those parameters in the main report an link them somehow.

I've tried creating parameters with the same name, I've tried using the default expressions to use the main parameters, I've tried adding all the Parameters using the Parameters button in the Dataset properties for the table.

I'm not sure where to go from here. How do I link the main data set parameters, and the parameters for the dataset associated with my table.

Upvotes: 2

Views: 9661

Answers (1)

Gustavo Meira
Gustavo Meira

Reputation: 3063

You're using the Jaspersoft Studio, right?

If so, select your table. In the "Properties" box (usually on the right bottom corner), if you select the tab "Dataset" and scroll until the end of it, you may notice a "Parameters" button. There you can map expressions to each parameter you use in your table's dataset. So in these expressions you can use the parameters declared in your main report.

In your JRXML file, it would be something like (for a java.lang.String parameter):

...
<parameter name="MAIN_REPORT_PARAMETER" class="java.lang.String"/>
...
<subDataset name="Dataset1">
    ...
    <parameter name="DATASET_PARAMETER" class="java.lang.String"/>
    ...
</subDataset>
...
<jr:table xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd">
                <datasetRun subDataset="Dataset1">
                    <datasetParameter name="DATASET_PARAMETER">
                        <datasetParameterExpression><![CDATA[$P{MAIN_REPORT_PARAMETER}]]></datasetParameterExpression>
                    </datasetParameter>

                     ...
                </datasetRun>
...
</jr:table>

Upvotes: 4

Related Questions