Posts Tagged ‘tables’

Jasper Reports tutorial - part 2 - tables

Monday, March 16th, 2009

I never planned a “part 2″ about Jasper Reports, but the previous “tutorial” lacks a small concept: how do I make tables? It’s obvious, but only after you figure it out. If you downloaded Jasper Reports examples, you can look at “datasource” sample. Nice one, but not as simple as you may want.

I only want to add a basic table which row data comes from a Java Collection. It is very easy to adapt the JasperFiller: just change JREmptyDatasource with JRBeanCollectionDataSource.

Adapting JRXML is easy, too, but it not obvious for a newbie. I admit I expected something like a “table” element (blame years of HTML), but in JR, you only need to define the “detail” element with the contents you want to repeat for each element on DataSource. Create it as you want, tune the band height to the height of a row, and you have your HTML-ish table.

BTW, you need to define all fields at the top of your JRXML, since JR’s DataSources does not contains metadata.

As a last tip, keep these in mind:

  • <title> only appears on first page;
  • <pageHeader> and <pageFooter> appears on every page;
  • <lastPageFooter> apperars only on last page, REPLACING <pageFooter>