Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JasperReport: Purpose of the Details Band

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.

like image 731
IAmYourFaja Avatar asked Dec 05 '11 16:12

IAmYourFaja


People also ask

What is subreport in Jasper report?

A subreport is a report included inside another report. This allows the creation of very complex layouts with different portions of a single document filled using different data sources and reports.

How do I add a band to Jasper report?

You can create another detail band by right-clicking your detail band in the outline and choosing "create band". But to have another header and footer, I think you need to create a subreport for each table. Set up each table with its header and footer in their own report.

How do I create a group header in Jasper report?

A group can even have more than one header\footer band in the designer, for example to add an header to a group it's sufficent right click on the header element in the outline view (it dosen't matter if it has black color or lightgray because at the moment there aren't other headers) and select the option "Create Band" ...


2 Answers

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.

like image 192
JB Nizet Avatar answered Sep 20 '22 13:09

JB Nizet


The purpose of the detail band is to provide you with a model where you place and configure report elements. I don't think the relationship between a bean and detail band is one to one, since you can place many bean property elements in one bean. So, i would say the detail band is tightly tied to a collection of report bean elements.

One difference though, is the fact that detail band's functionality is irrelevant to how many beans/records you provide through a JRDataSource. The detail band will iterate through all of them until the data source is "consumed".

Furthermore, i personally find it very useful that the detail band allow you to iterate through a collection of bean properties. So, placing several properties in a detail band will iterate through all of them, before proceeding forward.

If you pass a null as DataSource you wont get any data on the report, and only static text will show up.

like image 37
Mechkov Avatar answered Sep 19 '22 13:09

Mechkov