Search code examples
javajasper-reportsdatasource

I have the problem with adding datasource to the subreport of my Jasper Report in Java


In main datasource I have a field "List someDto". And I need to add this field to subreport datasource. Maybe I can use some expression, that will return JRDataSource type?

report.addDetail(subreport(report()
                .addDetail(text(field("text", String.class)))
                .addDetail(image(fieldExpression("image")))
                .setDataSource(----*here i need to add field from main datasource*----)

Solution

  • Omg, I just use subDatasourceBeanCollection and replace .setDataSource from the report().setDataSource to subreport(...).setDataSource():

    report.addDetail(subreport(report() .addDetail(text(field("text", String.class))) .addDetail(image(fieldExpression("image")))) .setDataSource(subDatasourceBeanCollection("*here my field from main datasource")));