I have two tables to be printed in same page. Data for those tables will be supplied from a map from a custom data source. I need to implement it. I googled for implementing this task.
At that time I came across sub-reports concept, but I didn't get much info for how to implement sub-reports.
I have an idea of how to create sub-reports. But I don't know how to fill sub reports with customdatasource. That's my question. Please help me in achieving this.
Note: I tried to implement subreports, but I am getting an error. Here is the code I used for compiling subreports:
JasperPrint print = new JasperPrint();
JRPdfExporter exporter = new JRPdfExporter();
JasperDesign design, design1;
JasperReport report, report1;
JasperReport jasperReport;
JasperDesign jd1;
jd1 = JRXmlLoader.load("D:\\sub_report1.jrxml");
jasperReport = JasperCompileManager.compileReport(jd1);
Map parameters = new HashMap();
parameters.put("ReportTitle", "Table Report");
parameters.put("DataFile", "TableSource.java");
parameters.put("Subreport_1", jasperReport);
design = JRXmlLoader.load("D:\\sub_report2.jrxml");
report = JasperCompileManager.compileReport(design);
parameters.put("Subreport_2", report);
design1 = JRXmlLoader.load("D:\\master_report.jrxml");
report1 = JasperCompileManager.compileReport(design1);
JasperFillManager.fillReportToFile(report1, "D:\\master_report.jrprint", parameters, new TableDataSource());
exporter.setParameter(JRExporterParameter.JASPER_PRINT, print);
exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, "D:K\\Report.pdf");
exporter.exportReport();
JasperViewer.viewReport(print);
Here I have compiled subreport1
& subreport2
individually and added them as a parameter in map. Then I'm getting an error while filling it through masterreports. Please help me to compile the report.
Stack trace of the compiler error:
Exception in thread "main" net.sf.jasperreports.engine.JRRuntimeException: Unkown print order 0. at net.sf.jasperreports.engine.fill.JRFillSubreport.initSubreportFiller(Unknown Source) at net.sf.jasperreports.engine.fill.JRFillSubreport.evaluateSubreport(Unknown Source) at net.sf.jasperreports.engine.fill.JRFillSubreport.evaluate(Unknown Source) at net.sf.jasperreports.engine.fill.JRFillElementContainer.evaluate(Unknown Source) at net.sf.jasperreports.engine.fill.JRFillBand.evaluate(Unknown Source) at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillColumnBand(Unknown Source) at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillDetail(Unknown Source) at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportStart(Unknown Source) at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(Unknown Source) at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(Unknown Source) at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(Unknown Source) at net.sf.jasperreports.engine.fill.JRFiller.fillReport(Unknown Source) at net.sf.jasperreports.engine.JasperFillManager.fillReport(Unknown Source) at net.sf.jasperreports.engine.JasperFillManager.fillReportToFile(Unknown Source) at ReportTableCompiler.main(ReportTableCompiler.java:53)