Blank subreport in Jasper Reports

2019-08-03 03:53发布

I'm trying to launch a report that I created in iReport which contains a main report and a subreport. In iReport, the subreport launches fine and contains data, however when I try to launch it from within my java code, the subreport is blank.

What I've done so far:

  • I have a String parameter in the main report called "SUBREPORT" that is used to define the path to the subreport. E.g. value: "E:\java\ReportLauncher\reports\test_subreport1.jasper"

  • The subreport expression in the main report is set to: $P{SUBREPORT}

  • The subreport connection expression is: $P{REPORT_CONNECTION}

  • I also have a subreport parameter defined called "INVOICE_NUMBER" that is set to $F{InviInvNo}, which maps to a field in the main report.

In my java code, I have:

HashMap<String, Object> paramHash = new HashMap();
paramHash.put("INVOICE_NUMBER", invoiceID);
paramHash.put("REPORT_CONNECTION", this.conn);
paramHash.put("SUBREPORT", subReportPath);

JasperPrint jasperprint = JasperFillManager.fillReport(this.reportPath, paramHash, this.conn);

The main report is created fine and is populated. The subreport area however is blank. Any thoughts for what I'm doing wrong?

Thanks in advance, Andy.

1条回答
乱世女痞
2楼-- · 2019-08-03 04:29

Since you didn't mention anything about the subreport query:

If you are using the Detail Band in the subreport, then you will need a Data Query for the report.

In old iReport, from Data menu, choose Report Query and write your query here. If you want only one record (i.e. Detail band only one time) you can use a dummy table. Like:

SELECT 'a' FROM DUMMY

Otherwise, if you don't want to use the Detail Band, you have the option to view the other bands without using a query. From Edit menu, choose Report Properties, under More... tab, set the flag When no data to All Sections, no detail

查看更多
登录 后发表回答