How to return variables from Report to Java

How can I return value of variable from jasper report to caller java code?

set report parameters
run report
get some variable back from report
make decision depending on previous step


Map parameters = new HashMap();
parameters.put(key, "value");

JasperPrint jasperPrint = JasperFillManager.fillReportToFile(fileName, parameters, getConnection());

String pageCount = jasperPrint.getVariableValue("PAGE_COUNT"); //METHOD NOT EXISTS, just fantasy


I believe this issue could be solved using scriptlet, but I have no idea how to return something from scriptlet in multithreaded environment.
vmstepanov's picture
Joined: Aug 16 2006 - 2:06am
Last seen: 7 years 9 months ago

1 Answer:

BaseReportFiller filler = (BaseReportFiller) JRFiller.createReportFiller(DefaultJasperReportsContext.getInstance(), jasperReport);
JasperPrint jPrint = filler.fill(parameters, getConnection());
Object pageCount = filler.getVariableValue("PAGE_COUNT");

minu-moto's picture
Joined: Feb 26 2014 - 6:06am
Last seen: 5 years 2 months ago