Friday, July 3, 2009

To Develop jasper reports using hibernate in your Struts2 application these are the prerequisites
  • Download iReport tool from jasper soft http://www.jaspersoft.com/downloads, used to generate jrxml file , this file acts as a template to generate report. When we compile and export this file.
  • Download Struts2 Jasper Reports plug in from http://cwiki.apache.org/S2PLUGINS/jasperreports-plugin.html . This plug in exports the data to PDF, EXCEL,RTF,CSV and HTML reports.
Generating sample.jrxml files for hibernate data :
  1. Create a new empty report template
  2. Select Static Text and add Title for your report in "Title" band of the report.
  3. Add Column Titles in "Column Properties Band" as Static Text.
  4. Add properties of your Business Object(POJO) as fields to the template.In iReport tool in left side frame you will see elements of your reports.There in right click on Fields elements and add your BO properties as fields.
  5. While adding Fields choose data types as defined in your BO.Otherwise report compilation errors will arise.
  6. Drag and Drop added fields and arrange them in "Detail" band of the reports.
  7. Now comple the report sample.jrxml this will generate sample.jasper.
Using sample.jasper and Struts2 jasper plug in to generate pdf report:
  1. copy ireport.jar,jasperreports.jar and plugin jar into your application's /WEB-INF/lib directory
  2. Configure your struts.xml file, in package tags extends attribute add "jasper result".
  3. To generate report from an action add following result type.

sample.jasper
mySource
PDF


here mySource is a List object of BO's which you should populate in your action before returning jasper result from action.


Followers