MewZ
MewZ

Reputation: 121

How to use Grails with BIRT report and show BIRT web viewer

I installed the birt-report plugin on a Grails web application project but I cannot understand to use it. I have 2 use cases:

  1. Generate BIRT web viewer and show on GSP Page (Show chart report)
  2. Generate BIRT report to some other file format (PDF, Word, etc.)

Can anyone please provide examples of how to do this?

Upvotes: 5

Views: 1665

Answers (1)

Tal
Tal

Reputation: 194

Basically you can use the examples as mentioned on plugin documentation (http://grails.org/plugin/birt-report). 1. For generating HTML report use. Noticed that BIRT produces HTML and not GSP. you can render the output HTML inside your GSP page.

// generate html output and send it to the browser
 def show() {
     String reportName = params.remove('id')
     String reportExt = 'pdf'
     params.remove('action')
     params.remove('controller')
     params.remove('name')
     def options = birtReportService.getRenderOption(request, 'html')
     def result=birtReportService.runAndRender(reportName, params, options)
     response.contentType = 'text/html'
     response.outputStream << result.toByteArray()
     return false
 }
  1. generate pdf for download

    def downloadAsPDF() { String reportName = params.remove('id') String reportExt = 'pdf' params.remove('action') params.remove('controller') params.remove('name') def options = birtReportService.getRenderOption(request, 'pdf') def result=birtReportService.runAndRender(reportName, params, options) response.setHeader("Content-disposition", "attachment; filename=" +reportName + "."+reportExt); response.contentType = 'application/pdf' response.outputStream << result.toByteArray() return false }

Upvotes: 0

Related Questions