0

I'm printing a table (array list) and one column will contain the same value for all rows, which will be passed to report as parameter. I've tried to iterate over the list and print the parameter like below with no success.

        <staticText>
            <reportElement style="table_CH" x="948" y="490" width="54" height="20" backcolor="#CCCCCC" uuid="5f8ded52-e8fd-4fd0-8ea3-2b0aaed76545"/>
            <textElement textAlignment="Center" verticalAlignment="Middle">
                <font size="7" isBold="true" isItalic="true" isUnderline="false"/>
            </textElement>
            <text><![CDATA[Total from stock]]></text>
        </staticText>
        <componentElement>
            <reportElement x="950" y="510" width="51" height="20" uuid="6dfca79b-f554-41e3-b7ca-c6694759debd">
                <property name="net.sf.jasperreports.export.headertoolbar.table.name" value=""/>
            </reportElement>
            <jr:list xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" printOrder="Vertical">
                <datasetRun subDataset="dataset1" uuid="2f211526-7be4-45d9-a026-e542c773e07a">
                    <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{this_is_my_array_list})]]></dataSourceExpression>
                </datasetRun>
                <jr:listContents height="20" width="51">
                    <textField>
                        <reportElement x="0" y="0" width="51" height="20" uuid="db47b136-15c8-44aa-b694-d396043c2b82"/>
                        <textElement textAlignment="Center">
                            <font size="8"/>
                        </textElement>
                        <textFieldExpression><![CDATA[$P{this_is_my_constant_parameter_string}.toString())]]></textFieldExpression>
                    </textField>
                </jr:listContents>
            </jr:list>
        </componentElement>
cape
  • 424
  • 1
  • 3
  • 16
  • Duplicates: [JRBeanCollectionDataSource: How to show data from the java.util.List from JavaBean](https://stackoverflow.com/q/12209300/876298) – Alex K Apr 17 '18 at 18:30

1 Answers1

1

Elements placed in lists are evaluated in the context of the subdataset used by the list (in your case the subdataset named dataset1). Parameters defined in the report are part of the main dataset and are not automatically shared with subdatasets.

If you need to display a report parameter in a list, you'll have to define a parameter in the subdataset and pass it the value of the report parameter as part of the dataset run. You can use the same for the subdataset parameter or a different name (as shown below).

Something like this:

<subDataset name="dataset1" uuid="1a45bd64-6c6a-4b66-a676-db452e27f7a6">
    <!-- subdataset parameter -->
    <parameter name="this_is_my_subdataset_parameter"/>
    ...
</subDataset>
<!-- report parameter -->
<parameter name="this_is_my_constant_parameter_string"/>
...
            <c:list>
                <!-- pass the value to the subdataset parameter -->
                <datasetRun subDataset="dataset1">
                    <datasetParameter name="this_is_my_subdataset_parameter">
                        <datasetParameterExpression><![CDATA[$P{this_is_my_constant_parameter_string}]]></datasetParameterExpression>
                    </datasetParameter>
                    ...
                </datasetRun>
                <c:listContents>
                        <textField>
                            <reportElement/>
                            <!-- use the subdataset parameter in the list -->
                            <textFieldExpression><![CDATA[$P{this_is_my_subdataset_parameter}]]></textFieldExpression>
                        </textField>
                        ...
dada67
  • 4,723
  • 17
  • 19