A JavaBean 包含一个java.util.List。如何将此列表的数据显示在 JasperReports 文档的 Detail 区域中?
// Java source to generate the report ... // DataSource using JRBeanCollectionDataSource private static JRDataSource getDataSource() { Collection<BeanWithList> coll = ...; return new JRBeanCollectionDataSource(coll); } // JavaBean public class BeanWithList { private List<String> cities; // ... // Ensure a public getter for field extraction public List<String> getCities() { return this.cities; } } // jrxml file ... // Subdataset for iterating through the list <subDataset name="dataset1"> <field name="city" class="java.lang.String"> <fieldDescription><![CDATA[_THIS]]></fieldDescription> </field> </subDataset> // Detail band with jr:list component <detail> ... <componentElement> <!-- jr:list component --> <jr:list ...> <datasetRun subDataset="dataset1"> <!-- DataSource expression using JRBeanCollectionDataSource --> <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{cities})]]></dataSourceExpression> </datasetRun> <jr:listContents ...> <textField ...> <textFieldExpression><![CDATA[$F{city}]]></textFieldExpression> </textField> </jr:listContents> </jr:list> </componentElement> ... </detail> ...
此配置生成一个报告,显示 详细信息 范围内的列表数据。
其他相关问题解决此问题topic:
以上是如何在 JasperReports 的详细信息区域中显示 JavaBean 列表?的详细内容。更多信息请关注PHP中文网其他相关文章!