• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Creating a Data Table in Jasper Report

 
Ranch Hand
Posts: 211
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am using Jasper Reports and I am wondering how you can create a data-table-like element in your reports. What I want to do basically is create a report which display records in a data table. The records may vary in size (i.e. the number of rows may differ), so hardcoding the records into static XML elements is not an option. The data of the records by the way is coming from a Java Bean datasource, and not from a database query. I know Jasper Reports has no built-in element to handle data-table-like displays, which is quite frustrating and surprising since most reports require some tabular data for display. Can somebody please help, it will be greatly appreciated. Thanks in advance.

Eugene
 
Bartender
Posts: 1844
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JasperReports handles this quite well, actually. This is fairly easy is the number of rows is all that is changing. (If the columns change as well, you can fake it with a cross-tabulation report, but that is frustrating to work with in any reporting system).

Usually, I create a List of records in a subclass of the JRDataSource class and pass that datasource to the report. The Details section of the report is then repeated once for each record returned by the call to .next() in the datasource. Yyou have to implement the stepping-though-the-list code and the get-value-for-the-field code youself; I usually do something like:



Then, I implement the getFieldValue as basically a big switch method -- if the field name is "FOO" I return the value data.getFoo(). (Or, most of the time I just create lists of Maps and simply return data.get(fieldName));

There you go -- instant data table.
 
Eugene Abarquez
Ranch Hand
Posts: 211
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Wow! Thanks Joel this worked great for me. Cheers man!



Eugene
 
reply
    Bookmark Topic Watch Topic
  • New Topic