HOW-TO Define behavior when empty data source

JasperReport define 4 possible actions when the data source is empty. These actions are described below.

Using the DynamicReportBuilder

DynamicReportBuilder setWhenNoDataType(byte whenNoDataType)
  • DJConstants.WHEN_NO_DATA_TYPE_NO_PAGES: No pages at all
  • DJConstants.WHEN_NO_DATA_TYPE_BLANK_PAGE: A blank page
  • DJConstants.WHEN_NO_DATA_TYPE_ALL_SECTIONS_NO_DETAIL: Shows everything but hides the detail section and shows a special band called “WHEN NO DATA”.
  • DJConstants.WHEN_NO_DATA_TYPE_NO_DATA_SECTION: Hides the detail band and shows the “NoData” section.

These convenient methods are also available:

setWhenNoDataNoPages(), setWhenNoDataBlankPage(), setWhenNoDataAllSectionNoDetail() and setWhenNoDataShowNoDataSection()

Define When No Data Section text

Whe can also define a text to be shown when the data source is empty. Using the DynamicReportBuilder we can do like this

 DynamicReportBuilder setWhenNoData(String text, Style style)

or this

 setWhenNoData(String text, Style style, boolean showTitle, boolean showColumnHeader)

In the first call, by default the title and column header are also shown along with the “No data for this report” text.

In the second call we can choose independently to show or not the title and column header.

Test Description
ar.com.fdvs.dj.test.WhenNoDataTest Creates a simple report using an empty list as data source
Fork me on GitHub