How to add parameter from request body in JasperReports?

I am using JasperReports for to generate and export PDF file. I am not directly connected with datebase.Here is my code
@RequestMapping(value = "/pdfReport", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE)
public void downloadPDF(HttpServletResponse response, @RequestBody ReportTransport reportTransport) throws IOException, JRException {
    InputStream jasperStream = this.getClass().getResourceAsStream("report2.jrxml");
    JasperDesign design = JRXmlLoader.load(jasperStream);
    JasperReport report = JasperCompileManager.compileReport(design);
    Map<String, Object> parameterMap = new HashMap<>();
    List<ReportDescription> reportDescriptions = storageManager.getPDFReport(reportTransport);
    JRDataSource jrDataSource = new JRBeanCollectionDataSource(reportDescriptions);
    parameterMap.put("datasource", jrDataSource);
    JasperPrint jasperPrint = JasperFillManager.fillReport(report, parameterMap, jrDataSource);
    response.setHeader("Content-Disposition", "inline; filename=report.pdf");
    final OutputStream outputStream = response.getOutputStream();
    JasperExportManager.exportReportToPdfStream(jasperPrint, outputStream);

I create List of Report Descriptions and fill it through my storage manager. Then create new JRBeanCollectionDataSource according to model class.

It works fine however I need to add some information to PDF file from request body like ID and name (information about things user choose in request). It is not in model class and I don't know how to add and fill these fields. Any idea?

tom_40's picture
Joined: Apr 24 2018 - 12:38am
Last seen: 2 years 10 months ago

0 Answers:

No answers yet