TIBCOSoftware / jasperreports

JasperReports® - Free Java Reporting Library
https://community.jaspersoft.com/downloads/community-edition/
GNU Lesser General Public License v3.0
1.06k stars 404 forks source link

Expression evaluation: evaluate only once #192

Closed pandziak closed 3 years ago

pandziak commented 3 years ago

Hey. I'm trying to evaluate some expressions fetched from Jasper xml, but it happens only once. Not only once per expression for example or once per jasperReport object, but only once at all, only on first method call.

PDF is generating fine, everything evaluates good in the result report. But I need to evaluate some expression before that and I'm having problems with evaluation via JREvaluator.

One line snippet: JasperCompileManager.loadEvaluator(jasperReport).evaluate(expression)

(and here whole Java demo: https://github.com/pandziak/jasper-expression-evaluation/blob/main/src/main/java/pl/kwl/jasper/JasperMain.java )

First thought leads me to think that somewhere is some state used. And I would love to look for it and debug this evaluation, but I have problems with debbuger and I cannot go further than 'evaluate(expressionId)' inside this 'JREvaluator#evaluate(expression)'. Here: https://github.com/TIBCOSoftware/jasperreports/blob/master/jasperreports/src/net/sf/jasperreports/engine/fill/JREvaluator.java - line 313. And I'm having problems with finding out in my project, which implementation is used.

Does anyone tried to evaluate expressions outside this whole generating process via these JREvaluators? Is this the best solution (or only...) or maybe there is another way to do that?

Thanks in advance!

teodord commented 3 years ago

Have you looked at scriptlets? http://jasperreports.sourceforge.net/sample.reference/scriptlet/index.html#scriptlet

I hope this helps. Teodor

dadza commented 3 years ago

You need to evaluate expression for the compiled report (JasperReport) and not from the design report (JasperDesign). It only works the first time due to a coincidence in expression IDs.

See changes at https://github.com/pandziak/jasper-expression-evaluation/pull/1

pandziak commented 3 years ago

Thank You so much! Extremely fast answer :)