【问题标题】:I have the problem with adding datasource to the subreport of my Jasper Report in Java我在用 Java 将数据源添加到 Jasper 报告的子报告时遇到问题
【发布时间】:2020-01-31 16:02:40
【问题描述】:
在主数据源中,我有一个字段“List someDto”。我需要将此字段添加到子报表数据源。也许我可以使用一些表达式,返回 JRDataSource 类型?
report.addDetail(subreport(report()
.addDetail(text(field("text", String.class)))
.addDetail(image(fieldExpression("image")))
.setDataSource(----*here i need to add field from main datasource*----)
【问题讨论】:
标签:
java
jasper-reports
datasource
【解决方案1】:
天哪,我只是使用 subDatasourceBeanCollection 并将 .setDataSource 从 report().setDataSource 替换为 subreport(...).setDataSource():
report.addDetail(subreport(report()
.addDetail(text(field("text", String.class)))
.addDetail(image(fieldExpression("image"))))
.setDataSource(subDatasourceBeanCollection("*here my field from main datasource")));