I’m having a bit of an issue when generating jasper reports in java. The setup works perfectly in iReport IDE. The way I’m creating the report is as follows:
private void createReport(String dataSourceXml) throws JRException{
String outFilename = dataSourceXml.replace(".xml", ".pdf");
String main = res.getString("main_jrxml.dir");
String sub1 = res.getString("sub1_jrxml.dir");
String sub2 = res.getString("sub2_jrxml.dir");
String sub3 = res.getString("sub3_jrxml.dir");
JasperReport sub3Report = JasperCompileManager.compileReport(sub3);
JasperReport sub2Report = JasperCompileManager.compileReport(sub2);
JasperReport sub1Report = JasperCompileManager.compileReport(sub1);
JasperReport mainReport = JasperCompileManager.compileReport(main);
JRXmlDataSource xmlDatasource = new JRXmlDataSource(new File(dataSourceXml));
Map<String, Object> params = new HashMap<String, Object>();
params.put("sub1", sub1);
params.put("sub2", sub2);
params.put("sub3", sub3);
JasperPrint jasperPrint = JasperFillManager.fillReport(mainReport, params, xmlDatasource);
JasperExportManager.exportReportToPdfFile(jasperPrint, outFilename);
}
The report get created and all the subreports gets filled but not the main report.
Can anybody advice what might be the problem?
I was not able to figure out why the fields from main report are not being filled. I worked around it by simply adding another subreport instead and this is working fine for me.
Pity that Jasper documentation is so horrible.