I work at a report that need a subreport, so I want to pass datasource from a Java method to subreport, but I don't arrive at the correct way. Usually I use the followin piece of code to create my report. What is the correct way to send datasource to subreport?
Map<String, Object> param = new HashMap<>();
param.put("rapportNom", "Module");
param.put("PAR_IMAGE_BACKGROUND", "/dz/suivi/reporting/sources/BackgroundElit.png");
param.put("PAR_IMAGE_HEADER", "/dz/suivi/reporting/sources/headerElit.png");
param.put("SUBREPORT_DIR", "/dz/suivi/reporting/sources/moduleAllDetail_subreport1.jasper");
param.put("SUBREPORT_DATA", "LIST OF OBJECT");
return Reporting.printEtat(getClass().getResourceAsStream("/dz/suivi/reporting/sources/moduleAllDetail.jasper"),
param, new JRBeanCollectionDataSource(reportingModuleViewFacade.findById(module)));
If you have your datasource as a
List<MyBean>
as simple method is:Pass it in the parameter map
Define the parameter in jrxml
Create a JRBeanCollectionDataSource using your parameter
I wrote an article for programming and configuring jasperreport with report, subreport and datasources:
For subreport: