Friday, May 23, 2008

Report Empty (Blank page is displayed) When No Data is present/retrieved: Solution


A Common Problem arising in Jasper Reports is when there’s no data retrieved A blank (white) page is displayed. This can be corrected in two ways

The Easiest way is of course to correct it through iReport. Find out how to do it by reading this.

There’s another not-so-subtle way to do it. That is setting the option through Java Code.

Whatever the method we use to display our report, we would have to construct the JasperReport objet. Simply set the option like this:

JasperReport jasperReport = (JasperReport) JRLoader.loadObject(jasperTemplateURL);

jasperReport.setWhenNoDataType(jasperReport.WHEN_NO_DATA_TYPE_ALL_SECTIONS_NO_DETAIL);

The Method setWhenNoDataType can be set three values. All Three are Constants in the JasperReport Object.

  • jasperReport.WHEN_NO_DATA_TYPE_BLANK_PAGE
  • jasperReport.WHEN_NO_DATA_TYPE_NO_PAGES
  • jasperReport .WHEN_NO_DATA_TYPE_ALL_SECTIONS_NO_DETAIL

We can use them to set it to any of the options we want.