Search code examples
javajasper-reports

Jasperreport without data source


How do I display a jasperreport without a datasource. The report is suppose to receive parameters from the java application and display them.


Solution

  • The way I would do it is to still put all of your text fields, etc. into the detail band, then use a new JREmptyDataSource(1) as your datasource. I.e:

    filledReport = JasperFillManager.fillReport(report, parameters, new JREmptyDataSource(1));
    

    Passing the value 1 to the constructor will create a single virtual record in the datasource, so the detail band will be printed only once. I prefer this method as it means the report template is more similar to a normal report template. The alternative is to have a completely empty datasource and then put all of your content into a different band (e.g. column header).