Shashank gaur
Shashank gaur

Reputation: 55

call birt report from action class

I am developing a project in Java EE Struts 2 and Hibernate for airline reservations. Now my all work is done and I have to generate a ticket. Instead of generating a simple JSP or HTML ticket, I want to generate a downloadable report (like Crystal Reports in Java). I have my entire ticket info in a session that (as on internet) I can get on BIRT report using script.

I am totally new to BIRT and wanted to know how I can generate a BIRT report or maybe call its execution engine from one of my action classes. Any ready example will be a great help.

Upvotes: 0

Views: 1165

Answers (1)

batbaatar
batbaatar

Reputation: 5468

I guess you're trying to send PDF ticket to customers. Please create your template and pass parameters using these lines:

ReportAdminServiceRemote  birtAdmService = (ReportAdminServiceRemote)MXServer.getMXServer().lookup(“BIRTREPORT”);
byte[] abyte0 = birtAdmService .runReport(userInfo, reportName, appName, parameterData, filename, “pdf”);

Once you have the bytes generated you can do this way:

public String actionDownload() throws Exception{
    response.setHeader("Cache-Control", "no-cache");
    response.setHeader("Content-Disposition","attachment; filename=\"" + example.pdf+ "\"");
    response.setHeader("Expires", "0");
    response.setHeader("Cache-Control","must-revalidate, post-check=0, pre-check=0");
    response.setHeader("Pragma", "public");

    ByteArrayOutputStream baos = new ByteArrayOutputStream();   
    ByteArrayInputStream bis = new ByteArrayInputStream(abyte0);
    inputStream = bis;
    return SUCCESS;
}

All the credits goes to authors on these pages:

http://www.maximonews.com/?p=65

http://www.coderanch.com/t/432713/Struts/Struts-Files-DownLoad-Streaming-as

Upvotes: 1

Related Questions