Hi in this post we will see the overview of JasperReports and how to integrate into JSF application. JasperReports is the world's most popular open source reporting engine. It is entirely written in Java and it is able to use data coming from any kind of data source and produce pixel-perfect documents that can be viewed, printed or exported in a variety of document formats including HTML, PDF, Excel, OpenOffice and Word.
In Primeface library also use this JasperReports to generate the PDF, CSV and DOC formats with single line of code. see here. but its not flexible and we cant change template. so here we see the how to use JasperReports for create the template and integrate JSF 2.0.
Now create the simple JSF Application to retrieve the data from database using JPA, then create the template using iReport and then integrate into JSF application.
Java Persistence API is standard way to access the all ORM (Object Relational Mapping) tools like Hibernate, EclipseLink, TopLink,.. . These tools are internally use JDBC to access the database.
the Heart of JPA is consist of two parts
persistence.xml - Its xml file describe the persistence provider (ORM provider) and connection information like database URL, username and password. or data source.
Entity Classes - Its normal POJO class for each table in underlying table. This class is annotated with @Entity and some annotation provided by JPA. Its way to express and map the property in the class into table in the DB.
These entity class are manually we can create or using IDE tools like Net beans IDE provide "Entity Classes From Database" option to auto generate the Entity Classes. (See video in below)
Once these entity classes are created then we need to create CRUD methods to wrapping these entities for ease of use. These kind of classes also auto generate from "Session Beans from Entity Classes" option.
Here we using GlassFish Server 3. Its supports EJB 3.1.
Now we create the JSF page to display the entity classes in table structure and provide buttons for export into variety of formats.