Java Reference
In-Depth Information
Integrating JasperReports
with other Frameworks
In previous chapters, we have seen several examples of web-based applications
generating reports and streaming them to the browser. In those examples, we
have been using 'raw' servlets to generate reports. Most modern Java web-based
applications are written using one of several web application frameworks. In this
chapter, we will discuss how to integrate JasperReports with three of the most
popular Java web application frameworks, Spring Web MVC , JavaServer Faces ,
and Struts .
In addition to using a web application framework, most modern Java projects use
an Object-Relational Mapping tool for database access. In this chapter, we will cover
how to generate reports with database data obtained using Hibernate, the most
popular Java Object-Relational Mapping tool.
Please note that this chapter assumes some familiarity with the above frameworks.
Feel free to skip to the sections that apply to frameworks used in your project.
Integrating JasperReports with Hibernate
Hibernate ( http://www.hibernate.org ) is a very popular Object-Relational
Mapping tool. JasperReports (version 1.2 and newer) includes native support for
Hibernate integration. This integration consists of allowing embedded report queries
to be written in the Hibernate Query Language (HQL) . The following JRXML
template illustrates how to do this:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jasperReport PUBLIC "//JasperReports//DTD Report Design//EN"
//JasperReports//DTD Report Design//EN"
"http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">
"//JasperReports//DTD Report Design//EN"
http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">
<jasperReport name="HibernateQueryDemoReport">
"http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">
Search WWH ::




Custom Search