Reputation: 11
I want to access a VARIABLE from a JasperReports in my Java code. More specifically, I need to know the REPORT_COUNT and the SUBREPORT_COUNT in my Java code after filling the report. I've tried setting it as a property, but that doesn't work.
The report is scheduled, and I do not want to send the email if there is no data. I've tried setting the "When No Data" to "print 0 pages," and then checking the page count in the java code. This doesn't work if there is data in just the main or the just the subreport. I want it to print 0 pages if either the main or the subreports have no data.
I'm sure this has been asked, but I can't find exactly what I need. If someone could point me in the right direction, it would be appreciated.
Upvotes: 0
Views: 1688
Reputation: 11
@brunobastosg This won't work if we have reports that return one row with all null fields and 0 in data_found, in this case, you can't tell if it's really no data or not.
Upvotes: 0
Reputation: 1426
Try the following:
JasperReport jasperReport = (JasperReport) JRLoader.loadObject("path/to/your.jasper");
// prior to version 4.6.0, you should use JRFiller.createFiller(jasperReport)
JRFiller.createFiller(DefaultJasperReportsContext.getInstance(), jasperReport);
JasperPrint print = filler.fill(yourParameterMap, yourDatasource);
Object value = filler.getVariableValue(variableName); // here's what you need
Be advised that you won't be able to use JasperFillManager.fillReport
anymore.
Upvotes: 2