Call Java method in Birt Report [message #1829542] |
Mon, 06 July 2020 12:17 |
Eclipse User |
|
|
|
I am having requirement of calling a JAVA method in Birt report , rptdesign file. I followed the example given in below URL.
https://download.eclipse.org/birt/downloads/examples/scripting/scripteddatasource/javacode/
JAVA class URL:
https://download.eclipse.org/birt/downloads/examples/scripting/scripteddatasource/javacode/SimpleClass.java
rptdesign file URL:
https://download.eclipse.org/birt/downloads/examples/scripting/scripteddatasource/reports/ScriptedDatasourceExampleAfter.rptdesign
As given in this example, I called my java class exactly the same way as below.
1. <method name="open"><![CDATA[favoritesClass = new Packages.SampleRowUpdater();
favorites = favoritesClass.readData(dataSetRow["LASTUPDATEDUSER"]);
totalrows = favorites.size();
currentrow = 0;]]></method>
This code works fine and no exception shown in logs as well. But also no logs are getting printed which I have added to check if method is getting called or not. It seems with this approach method is not getting called.
When I do little bit changes as method name="initialize" as below
2. <method name="initialize"><![CDATA[favoritesClass = new Packages.SampleRowUpdater();
favorites = favoritesClass.readData(dataSetRow["LASTUPDATEDUSER"]);
totalrows = favorites.size();
currentrow = 0;]]></method>
I am getting below exception.
TypeError: [JavaPackage SampleRowUpdater] is not a function, it is object. (/report/method[@name="initialize"]#1)
at org.eclipse.birt.report.engine.javascript.JavascriptEngine.evaluate(JavascriptEngine.java:295)
at org.eclipse.birt.core.script.ScriptContext.evaluate(ScriptContext.java:159)
at org.eclipse.birt.report.engine.executor.ExecutionContext.evaluate(ExecutionContext.java:789)
at org.eclipse.birt.report.engine.executor.ExecutionContext.evaluate(ExecutionContext.java:718)
at org.eclipse.birt.report.engine.script.internal.ScriptExecutor.handleScriptInternal(ScriptExecutor.java:118)
at org.eclipse.birt.report.engine.script.internal.ScriptExecutor.handleScript(ScriptExecutor.java:105)
at org.eclipse.birt.report.engine.script.internal.ReportScriptExecutor.handleInitialize(ReportScriptExecutor.java:84)
... 77 more
Caused by: org.mozilla.javascript.EcmaError: TypeError: [JavaPackage SampleRowUpdater] is not a function, it is object.
I am not sure if this is the right method or we can use handler as well. I tried following some examples of Handler creation but I didn't get how to use the handler in Birt again. I am new to Birt. I am not aware which is the best way to use java class in birt report and how to use java class method in Birt report.
I request for help.
|
|
|
Powered by
FUDForum. Page generated in 0.09965 seconds