How is Vector <Vector> Receipt used as a JasperReports DataSource from Java?

I have a Vector receiptOrder and I want to print this receipt to a thermal printer using iReport


I am getting 3 classes:

  • MyDataSource, which implements JRDataSource

  • MyDataSourceProvider, which implements JRDataSourceProvider

  • JRBasicField, which implements JRField

How can I set up a datasource JasperReports

with this vector?

  • I did it.

    • upload jrxml


      JasperDesign jasperDesign = JRXmlLoader.load ("c: /PrintReceipt.jrxml");
      JasperReport jr = JasperCompileManager.compileReport (jasperDesign);
    • pass orderRows

      which is from Vector<Vector>

      to MyDataSourceProvider

      , then createdatasource

      JRDataSourceProvider dsp = new MyDataSourceProvider (orderRows);
      JRDataSource dataSource = dsp.create (jr);
      JasperPrint jasperPrint = JasperFillManager.fillReport (jr, new HashMap (), dataSource);
      JasperExportManager.exportReportToPdfFile (jasperPrint, "c: /test.pdf");
      JasperViewer.viewReport (jasperPrint);
  • but JasperReport shows me an empty view as well as test.pdf


  • any idea ...?


source to share

1 answer

  • I fixed my problem.
  • Problem due to MyDataSourceProvider fields

    mismatchireport.jrxml fields

  • After I fix this issue everything works fine.



All Articles