jasper-reports

Accessing report parameter in chart Customizer code


I'm implementing the answer here accessing parameter in customizer

I defined parameter like

<categoryDataset>
                <dataset>
                    <datasetRun subDataset="chartDataset">
                        <datasetParameter name="SOME_CHART_PARAM">
                            <datasetParameterExpression><![CDATA[$P{SOME_PARAM}]]></datasetParameterExpression>
                        </datasetParameter>

While running, I got error like

 1. Unknown parameter SOME_CHART_PARAM in dataset chartDataset.

So I tried adding a parameter as below.

    <subDataset name="chartDataset" uuid="f9034d6f-c83f-446d-a1ef-ade237677df0">
        <queryString>
            <![CDATA[]]>
        </queryString>
        <field name="month" class="java.lang.String"/>      
        <parameter name="SOME_CHART_PARAM" class="java.lang.String"/>
    </subDataset>

But got SAXParseException seems parameter not allowed inside subDataset.

 Invalid content was found starting with element '{"http://jasperreports.sourceforge.net/jasperreports":parameter}'. One of '{"http://jasperreports.sourceforge.net/jasperreports":field, "http://jasperreports.sourceforge.net/jasperreports":sortField, "http://jasperreports.sourceforge.net/jasperreports":variable, "http://jasperreports.sourceforge.net/jasperreports":filterExpression, "http://jasperreports.sourceforge.net/jasperreports":group}' is expected.

Tried to add through JasperStudio but add parameter does not provide option to manually edit parameter name.

enter image description here


Solution

  • The parameter needs to be defined in the subdataset before the query string:

    <subDataset name="chartDataset" uuid="f9034d6f-c83f-446d-a1ef-ade237677df0">
        <parameter name="SOME_CHART_PARAM" class="java.lang.String"/>
        <queryString>
            <![CDATA[]]>
        </queryString>
        <field name="month" class="java.lang.String"/>      
    </subDataset>
    

    In Jaspersoft Studio you need to define the parameter in the Outline view under the subdataset/Paramters, select the parameter in the Outline view and set its name in the Properties view.

    Subdataset parameter in Jaspersoft Studio