I know,By using <g:Jasper> tag I can generate report in grails but I want to save the report generated directly to a folder,mostly using method, iss any of you have any Idea regarding this
Generating jasper report by using method call in grails
297 Views Asked by Abdulla I At
2
There are 2 best solutions below
0
On
I hope you are asking to save jasper generated report to a file. This is easy. You can obtain report content (as byet array) from jasper. Then just save the content to a file. An example is given below-
JasperService jasperService;
def saveReport(GrailsParameterMap params, Locale locale, List<DataModel> models) {
// Prepare data
List searchReportSheet = new ArrayList();
LinkedHashMap<String, Object> searchSheetMap;
models.each {
searchSheetMap = new LinkedHashMap<String, Object>();
searchSheetMap.put("key", it.keyValue);
...............
...............
searchReportSheet.add(searchSheetMap);
}
// Call jasper for generate report
def reportDef = jasperService.buildReportDefinition(params, locale, [data: searchReportSheet]);
// Save to File
def content = reportDef.contentStream.toByteArray();
FileOutputStream fileOuputStream = new FileOutputStream(fileDest)
fileOuputStream.write(content);
}
Let's say your controller
conand methodmetexecute the jasper report export. And inparamsyou pass some parameters. Let's say the parameters arename, reportFile, 'date.Then you can get the report export by calling this link from any where:
For example: I recently exported a jasper report using this link: