Interface JRExport<R>

Type Parameters:
R - the export result type

public interface JRExport<R>
Exports a filled report.

Applied by JasperReports.export(JRReport, JRExport), which runs the export wherever the report is filled. Filling a report through an EntityConnection runs it on the server, so a report exported to PDF reaches the client as bytes, which no reporting engine is required to read.

 ReportType<Map<String, Object>, byte[]> REPORT = reportType("customer_report");

 add(REPORT, export(classPathReport(Store.class, "customer_report.jasper"), PDF));

Exports beyond the ones defined here are lambdas, JasperReports exporters all following the same shape:

 JRExport<byte[]> xlsx = print -> {
   ByteArrayOutputStream bytes = new ByteArrayOutputStream();
   JRXlsxExporter exporter = new JRXlsxExporter();
   exporter.setExporterInput(new SimpleExporterInput(print));
   exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(bytes));
   exporter.exportReport();

   return bytes.toByteArray();
 };
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final JRExport<byte[]>
    Exports to PDF.
    static final JRExport<net.sf.jasperreports.engine.JasperPrint>
    The identity export, the filled report itself.
    static final JRExport<byte[]>
    Serializes the filled report to bytes, reconstructed with JasperReports.loadPrint(byte[]).
    static final JRExport<String>
    Exports to the JasperReports XML print format.
  • Method Summary

    Modifier and Type
    Method
    Description
    export(net.sf.jasperreports.engine.JasperPrint print)
     
  • Field Details

    • PRINT

      static final JRExport<net.sf.jasperreports.engine.JasperPrint> PRINT
      The identity export, the filled report itself.

      Requires JasperReports wherever the result is received, JasperPrint being a JasperReports type, serialized when the report is filled through a remote connection.

    • SERIALIZED

      static final JRExport<byte[]> SERIALIZED
      Serializes the filled report to bytes, reconstructed with JasperReports.loadPrint(byte[]).

      The JasperPrint itself, unlike PRINT, but carried as a byte[], which any connection transfers, a JSON one included, where a JasperPrint cannot go. A client with the reporting engine, one displaying reports with a JRViewer, can therefore keep filling them to a JasperPrint over any connection, reconstructing it from the bytes:

       ReportType<Map<String, Object>, byte[]> REPORT = reportType("customer_report");
      
       add(REPORT, export(classPathReport(Store.class, "customer_report.jasper"), SERIALIZED));
      
       //client side, with the engine on hand
       JasperPrint print = loadPrint(connection.report(REPORT, parameters));
      

      The bytes are the report's own Java serialization, so a client reconstructing them needs the net.sf.jasperreports.engine.** classes allowed by any deserialization filter it applies, the same classes a server loading a .jasper file needs.

      See Also:
    • PDF

      static final JRExport<byte[]> PDF
      Exports to PDF.

      Requires the net.sf.jasperreports:jasperreports-pdf artifact, which is not a dependency of this plugin. It registers itself through a jasperreports_extension.properties resource, which is scanned off the classpath, so nothing requires its module and it is neither resolved on the module path nor included in a jlink image unless named explicitly, via --add-modules net.sf.jasperreports.pdf. A missing extension surfaces as a ReportException when the report is filled.

    • XML

      static final JRExport<String> XML
      Exports to the JasperReports XML print format.
  • Method Details

    • export

      R export(net.sf.jasperreports.engine.JasperPrint print) throws net.sf.jasperreports.engine.JRException
      Parameters:
      print - the filled report to export
      Returns:
      the exported report
      Throws:
      net.sf.jasperreports.engine.JRException - in case of an exception