Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » BIRT » birt List java bean as dataSource
birt List java bean as dataSource [message #798581] Tue, 14 February 2012 21:33 Go to next message
zubin Missing name is currently offline zubin Missing nameFriend
Messages: 32
Registered: July 2009
Member
Hello,

Is there any way to use a java.util.list as dataSource that pass in to birt?

for example following are the code to export pdf format out:

public byte[] createPDF(final IReportRunnable design,
List<Map<String, Object>> records) throws Exception {
PDFRenderContext renderContext = new PDFRenderContext();
HashMap contextMap = new HashMap();
contextMap.put(EngineConstants.APPCONTEXT_PDF_RENDER_CONTEXT,
renderContext);
HTMLRenderOption options = new HTMLRenderOption();
ByteArrayOutputStream out = new ByteArrayOutputStream();
options.setOutputStream(out);
options.setOutputFormat("pdf");

IRunAndRenderTask task = birtEngine.createRunAndRenderTask(design);

task.setAppContext(contextMap);
task.setRenderOption(options);
task.run();
task.close();
return out.toByteArray();
}


task.close();
return out.toByteArray();


records is the list of result that should use as datasource. is there a way to do it in birt.

thanks
Re: birt List java bean as dataSource [message #798836 is a reply to message #798581] Wed, 15 February 2012 06:12 Go to previous messageGo to next message
Ludwig Moser is currently offline Ludwig MoserFriend
Messages: 476
Registered: July 2009
Senior Member
i try to do this too and i think i nearly got it.
what i do is i generate a POJO rptdesign from my list (with an empty design yet)
i generate the datasource and the dataset including the javascript functions from my data

i do not want to go into details as its not finished yet, but if it works i'll let you know (or someone else posts the solution here)
Re: birt List java bean as dataSource [message #799227 is a reply to message #798581] Wed, 15 February 2012 16:15 Go to previous message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

Yes. Before you run the report load the records field into the app
context like:

task.getAppContext().put("myrecords", records);

The report can then be written to use a scripted data source
http://www.eclipse.org/birt/phoenix/examples/scripting/scripteddatasource/
to read the values. In the scripted data set open method your can get
access to the records like:

myrecords = reportContext.getAppContext().get("myrecords");

You should then be able to use the fetch method to iterate over myrecords.

Jason

On 2/14/2012 4:33 PM, zubin Mising name wrote:
> Hello,
>
> Is there any way to use a java.util.list as dataSource that pass in to
> birt?
>
> for example following are the code to export pdf format out:
>
> public byte[] createPDF(final IReportRunnable design, List<Map<String,
> Object>> records) throws Exception {
> PDFRenderContext renderContext = new PDFRenderContext();
> HashMap contextMap = new HashMap();
> contextMap.put(EngineConstants.APPCONTEXT_PDF_RENDER_CONTEXT,
> renderContext);
> HTMLRenderOption options = new HTMLRenderOption();
> ByteArrayOutputStream out = new ByteArrayOutputStream();
> options.setOutputStream(out);
> options.setOutputFormat("pdf");
>
> IRunAndRenderTask task = birtEngine.createRunAndRenderTask(design);
>
> task.setAppContext(contextMap);
> task.setRenderOption(options);
> task.run();
> task.close();
> return out.toByteArray();
> }
>
>
> task.close();
> return out.toByteArray();
>
>
> records is the list of result that should use as datasource. is there a
> way to do it in birt.
>
> thanks
Previous Topic:Image(chart) not display in HTML report
Next Topic:how to arrange data horizontally and vertically
Goto Forum:
  


Current Time: Thu Apr 25 08:49:53 GMT 2024

Powered by FUDForum. Page generated in 0.03324 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top