Creating/Passing Java bean Datasource in JasperReport

不想你离开。 提交于 2019-11-30 07:20:20

If you already have a DataSource then you can pass your List/Map thourgh the param Map when you're filling your report.

Map<String, Object> param = new HashMap<String, Object>();
param.put("SUB_DATA_SOURCE", yourList);

JasperFillManager.fillReport(jasperReport, param,
                new JRBeanCollectionDataSource(yourMainListHere));

Doing that you have to create a parameter inside your MAIN report with the same name you have set in your param Map and also give to this a Type Class (List in my case).

Than you have to create your subreport element and set the Connection Type as "Use a datasource expression" and inside the "Data Source Expression" you set this:

new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($P{SUB_DATA_SOURCE})
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!