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)
How to pass my collection to the report?
Jesfre
Hi everybody,
I have a collection of objects ready to export to a Birt Excel report. But I didn't found a way to pass this collection to my report. I just want to iterate this collection of objects to populate the report like I can do with Jasperreports.
Somebody knows a tutorial to do this?
Thanks...
Find more posts tagged with
Comments
mwilliams
Have you looked into using a scripted data set?
http://www.birt-exchange.org/org/devshare/designing-birt-reports/255-birt-scripted-datasource-example-design/
Jesfre
<blockquote class='ipsBlockquote' data-author="'mwilliams'" data-cid="114850" data-time="1362602561" data-date="06 March 2013 - 01:42 PM"><p>
Have you looked into using a scripted data set? <br />
<br />
<a class='bbc_url' href='
http://www.birt-exchange.org/org/devshare/designing-birt-reports/255-birt-scripted-datasource-example-design/'>http://www.birt-exchange.org/org/devshare/designing-birt-reports/255-birt-scripted-datasource-example-design/</a><br
/></p></blockquote>
<br />
That looks easy, but I'm using singleton services, so the best that I can do is to put the collection into the session layer of the webapp. There is some way to obtain the currecnt session and get an attribute, cast into a collection and iterate it to populate the report? <br />
The thing is that I dont want to run the entire process again to filter the collection, because of performance... <br />
<br />
Some way to do this simple thing without fetch again like the favoritesClass.readData()?<br />
I'm looking a workaround to follow the example and to use the ready-to-use collection.<br />
Thanks.
CBR
You have got multiple solutions (i only mention 2 for the moment):<br />
<br />
1) Session attribute:<br />
Your proposal just works. Simply place collection in session. BIRT provides ability to get informations from the context in which BIRT is running. All important informations can be obtained within the report itself using the global reportContext variable. To get the session use<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
var request = reportContext.getHttpServletRequest();
var session = request.getSession();
myCollection = session.getAttribute("collection");
</pre>
This should be placed in beforeFactory event of the report. Please remind that myCollection is missing the var keyword and therefore is a global variable within the report. In addition you do not need to cast because Rhino is a untyped language anyways, so it is missing type information and therefore is not even interested in the type. It will automatically resolve the type at runtime. All will be fine, if you make sure that your session attribute is a collection, if it is not it will break during runtime but will not during report design.<br />
After initializing this global variable you could simply use it within a scriptedDataSet. Basically the same way you already mentioned.<br />
Two problems:<br />
a) The content of the collection must be serializable..otherwise you do not have a chance to set it as a session attribute.<br />
It will become a real problem if the collection is large because session will be overloaded with data and therefore will slow down the whole server<br />
<br />
2) Use the appContext:<br />
this is by far the better approach because it is directly handing the collection itself over to BIRT. You can only use this technique if you are generating the reports directly using the report engine.<br />
Therefore the Run and the RunAndRender task have a method getAppContext(). This is returning a Map<String, Object> that can be used to share information with the BIRT report.<br />
Simply use:<br />
<br />
In Java<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
Collection<...> col = ...//this is your collection that you want to share
RunAndRenderTask task = ...
task.getAppContext().put("myCollection", col);
task.run()...
</pre>
<br />
In BIRT beforeFactory:<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
myCollection = reportContext.getAppContext().get("myCollection");
</pre>
Everything else will be the same as 1)
Jesfre
I decided the second way, because the 1st approach works but, cbrell is right, a long data collection in session can overload the server.
Thanks cbrell and mwilliams.