Java – JasperReport: Purpose of the Details Band

jasper-reportsjava

I figured this would be something that would be fairly-well documented as its a central theme to JasperReports, however I can't find an answer for this anywhere.

What is the purpose/function/intention of a details band? Is it supposed to just be the central or core part of a report?

From another question it was pointed out to me that there is a 1:1 relationship between a details band and a record/bean provided by the JRDatasource. This revelation brings to light a few tangential questions:

  • It is possible to add detail bands programmatically in Java; what happens if you specify more/less detail bands (programmatically) than there are records/beans returned by your JRDataSource?
  • What is the relationship between a details band, and say, a page inside an exported PDF document? Does 1 details bands translate to 1 page?
  • What happens if you pass the JasperFillManager a null data source? Is it possible to still have detail bands?

I don't like to ask multiple questions at a time, but these are so similarly-related I'd rather do it all at once than clutter SO with multiple nearly-identical questions. Thanks in advance.

Best Answer

The details band is indeed the band where each element of the data source is reported. The report engine automatically iterates over the data source and inserts data into the template of the detail band with respective element of the data source.

You may of course have several elements on a single page. According to the properties of the band (split allowed, height, etc.), the paging will be handled by Jasper Reports automatically, and it's the engine that will thus decide how many elements are printed on each page, when to go to the following page, etc.

The details band is not printed if you have nothing in the data source. The printing of the other bands depend on the parameters of the report.