Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Java Object as Report Parameter
kosta
Hello BIRT community,<br />
<br />
is there any way to pass Java Object as report parameter to the report.<br />
In der Report Designer GUI there are several types of parameter listed like:<br />
<ul class='bbc'><li> Boolean</li><li> Date</li><li> Date Time</li><li> Decimal</li><li> Float</li><li> Integer</li><li> String</li><li> Time</li></ul>
but not Java Object.<br />
<br />
Thanks in advance for any hint and advice.
Find more posts tagged with
Comments
CBR
You are right. These are the only parameter types available. You can't pass any other object to your report using a report parameter.
My suggestion would be to use the appContext hashMap to pass any kind of java object to your report. Another possibility would be to encrypt a java object as a string and decrypt it in the report (might be too complex).
kosta
Thank you for the answer cbrell,
about the first suggestion:
- BIRT API: since I am using BIRT API alls java object's are pass to BIRT over the setAppContext-method as part of the IRunAndRenderTask implementation.
In the rptlibrary I am using here dataSets as container to get the object.
There I can try to pass the object to a parameter or a global script variable.
- Report Designer in eclipse: How can I pass java object's over the appContext that using only the report designer.
I know that the classes are set to the classpath via the eclipse->Pereferences->Report Design->Classpath.
about the second suggestion:
You mean here to serialize the java object and make a string from the input steam of the binary file of it?
How can you then invoke deserialization or decryption in BIRT ?
For any suggestion and hints thanks in advance.
CBR
If you are using libraries BIRT will take care that the original appContext is passed to the library at runtime if the report imports this library. You do not need to pass it yourself.<br />
You can simply use a global variable in your report. The only thing that is to remember is that your object needs to implement the Serializable interface if you want to store it as a persistent global variable (only if you use reportContext.setGlobalPersistentVariable(..., yourObject))<br />
<br />
Concerning the designer issue: Since BIRT 2.3 it is possible to create a dedicated appContext that is passed as a dummy to your reports to be able to preview them correctly: See <a class='bbc_url' href='
http://www.eclipse.org/birt/phoenix/project/notable2.3M6.php#jump_5'>http://www.eclipse.org/birt/phoenix/project/notable2.3M6.php#jump_5</a>
; The bad thing is that you have to write a small plugin that does the job for you. This plugin is only to be used in the designer and enables you to provide some custom values in the appContext for the Designer.<br />
<br />
Concerning serialization:<br />
You are correct. I was talking about serializing the object to a string. You can invent your own format too (like some JSON style format). The basic idea is to make a simple string out of a complex object. Inside your report you need to parse that string to get back the object (you can use Java inside Rhino to do that). The disadvantage is that a user has to manually enter this string as a report parameter when he wants to do a preview in the designer.<br />
<br />
<br />
<blockquote class='ipsBlockquote' data-author="'kosta'" data-cid="102643" data-time="1339399194" data-date="11 June 2012 - 12:19 AM"><p>
Thank you for the answer cbrell,<br />
<br />
about the first suggestion:<br />
- BIRT API: since I am using BIRT API alls java object's are pass to BIRT over the setAppContext-method as part of the IRunAndRenderTask implementation.<br />
In the rptlibrary I am using here dataSets as container to get the object.<br />
There I can try to pass the object to a parameter or a global script variable. <br />
<br />
- Report Designer in eclipse: How can I pass java object's over the appContext that using only the report designer. <br />
I know that the classes are set to the classpath via the eclipse->Pereferences->Report Design->Classpath.<br />
<br />
about the second suggestion:<br />
You mean here to serialize the java object and make a string from the input steam of the binary file of it? <br />
How can you then invoke deserialization or decryption in BIRT ?<br />
<br />
For any suggestion and hints thanks in advance.<br /></p></blockquote>
kosta
Thanks for the answer cbrell,
reportContext.setGlobalPersistentVariable(..., yourObject)) works fine wenn using it into rptdesign file.
How can use this piece of code if I am creating the ReportDesignHandle on runtime.
I don't have any methods to access the reportContext.
On ohter side and the rptlibraries doesn't have the report global methods like the design files where global variables can be declared.
For any suggestion and hints thanks in advance.
kosta
I have just tested that you can set Objects with the setParameterValue-method.
I 'll try that for my application.
CBR
Hi Kosta,
so you want to set a globalPersistentVariable in the render phase (so when executing a render task on a rptdocument)? Is that what you were asking?
If yes:
The idea of a global persistent variable is as follows:
We set a global variable in the run phase and we want to ensure that it can be accessed in the render phase regardless of the concrete model that we use (RunAndRender or Run to create an rptdocument and sometime later run Render on that rptdocument).
The reason why it is called PersistentGlobalVariable is that the variable and it's current value will be serialized into the rptdocument if we use Run and then Render.
the reason why you can't use this method in the render phase is that you won't be able to persist it somewhere. The other reason is that it would just be the same thing as a global variable (no gain in persisting it somewhere because we are already at the end of the workflow).
Does this make sense for you?
kosta
I don't understand evertyhing but you want to explain that setting the globalPersistentVariable in the Run or RunAndRender doesn't make sence because is to late then.
I thought, if I can set globalPersistentVariable in the rptdesign by typing it in the file I can also set it via some API-method if my rptdesign is handled as java object using the DEAPI (org.eclipse.birt.report.model.api.ReportDesignHandle).
Thanks for the explanation.