將資料傳遞給子報表

這是主報告的片段。藉助 net.sf.jasperreports.engine.data.JRBeanCollectionDataSource 建構函式將資料來源傳遞給子報表

<field name="someFieldWithList" class="java.util.List"/>
<!-- ...... -->
<subreport>
    <reportElement x="0" y="0" width="200" height="70"/>
    <parametersMapExpression><![CDATA[$P{REPORT_PARAMETERS_MAP}]]></parametersMapExpression>
    <dataSourceExpression><![CDATA[net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{someFieldWithList})]]></dataSourceExpression>
    <subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "subreport.jasper"]]></subreportExpression>
</subreport>