Jasper Reports First Look

Agenda

  1. Overview
  2. Requirements
  3. POC Activities
  4. Advantages
  5. Disadvantages
  6. Tools

Overview
Jasper Reports is open source reporting tool.
  • Jasper Reports is written in 100% Java. And can be embedded in any Java application.
  • JasperReports is an engine that takes an XML file and forms a report out of that file using the data source specified in the XML file.
  • Various output options PDF, HTML, XLS, CSV, XML, RTF, TXT files, or directly on the screen or printer.
  • Various data source options: JDBC, EJB, POJO, Hibernate, XML.
  • Integrated charting


Features

•It has flexible report layout.
•It is capable of presenting data textually or graphically.
•It allows developers to supply data in multiple ways.
•It can accept data from multiple data sources.
•It can generate watermarks. It can generate subreports.
•It is capable of exporting reports to a variety of formats.

Requirements
•Jar Files

  1. ojasperreports-2.0.2
  2. ocommons-beanutils-1.5
  3. ocommons-collections-2.1
  4. ocommons-digester-1.3
  5. ocommons-logging-1.0.2
  6. ocommons-logging-api-1.0.2
  7. oitext-1.01

http://web.1asphost.com/blufmaster/jasper/workflow.JPG

http://web.1asphost.com/blufmaster/jasper/technology.JPG



Structure of jrxml file

•Report designs.
•Parameters.
•Data Source.
•Fields.
•Expressions.
•Variables
•Report sections
•Groups
•Font and Unicode Support
•Sub reports.
•I18n support

JasperReport – Parameters
•Parameters are object references that are passed-in to the report filling operations.
•Parameters are useful for passing to the report engine that it can not normally find in its data sourcePublish Post
•Declaring a parameter in report design require specifying name and class :
•There are also the built-in system parameters :
  1. vREPORT_PARAMETERS_MAP
  2. vREPORT_CONNECTION
  3. vREPORT_DATA_SOURCE
  4. vREPORT_LOCALE




JasperReport – Data Source


•Jasper Reports support various types of data source using special interface called JRDataSource

•There is default implementation of this interface (JRResultSetDataSource class ) that wraps a Result object . It allows the use of any RDMS database through JDBC.

• When using a JDBC data source, one could pass a Connection object to the report filling operations and specify the query in the report definition itself with the XML definition in element:



JasperReport – Fields
•Report fields present the only way to map data from data source into the report generating routines.
•For example :
–The table has following structure :
http://web.1asphost.com/blufmaster/jasper/tabl%20str1.JPG





Define the following fields in our report design :







JasperReport – Expressions


•Expression can be used for declaring report variables that performs various calculations, for data grouping on the report , to specify report text fields content
•In an XML report design there are several elements in define expressions :
, , , , and .
•Example

$F{FirstName} + " " + $F{LastName} + " was hired on " + (new SimpleDateFormat("MM/dd/yyyy")).format($F{HireDate}) + "."


JasperReport – Variables

•Report variables is special objects build on of top expression and be used simplify the report design by declaring an expression.
•Variable can perform built-in types of calculations on their corresponding expression values like : count, sum, average, lowest , highest ….
•Example : $F{Quantity}

•Following built-in system variables :
  1. PAGE_NUMBER.
  2. COLUMN_NUMBER.
  3. REPORT_COUNT.
  4. PAGE_COUNT.
  5. COLUMN_COUNT.
  6. GROUPNAME_COUNT.




JasperReport – Groups Font and Unicode
•Groups represent a flexible way to organize data on a report and introduce the corresponding and section on the report.

JasperReport – sub report & i18n support

•Subreports are an import feature for a report-generating tool. They allow the creation of more complex reports and simplify the design work.

• The subreports are very useful when creating master-detail type of reports.

•With the i18n support in the jasper report , associating a java.util.ResourceBundle and with the value REPORT_LOCALE.



Advantages


•Handle complex reports, subreports with highly complex layouts, pixel-perfect page-oriented output for the Web or print, and crosstabbing, and output reports in PDF, XML, HTML, CSV, XLS, RTF, or TXT.
•Create integrated charting with comprehensive chart types.
•Use multilanguage Unicode and other native encodings, dynamic text localization, and localized date, number, and currency formatting. •Scale with high-performance report generation with no limit to report size. •Access data flexibly with JasperReport’s built-in support for JDBC, EJB, POJO, Hibernate, XML, and more.
•Extensive formatting capabilities

Disadvantages

•Not Properly Documented.
•Event Handling not possible.
•Can include external style sheets but has certain limitations.
•Changes to reports on the running application are limited.

Tools
•i-Reports
•Jasper Assistant for Eclipse


iReport
ØiReport is a visual tool to obtain XML files for JasperReports.
ØIt provides a WYSIWYG environment to design reports .
ØiReport is openSource program that can create complex reports which can use every kind of Java application through JasperReport library and written 100% pure Java.
Ø
Features
Ø99% support of JasperReport XML tags.
ØWYSIWYG editor for creation reports.
ØSupport for all database accessible by JDBC.
ØIntegrated report compiler and exporter.
ØVirtual support for all kinds of Data Sources.
ØSupport sub reports.
ØSupport for document templates
ØManagement of a library of a standard objects (number of pages ,..).
ØDrag’n drop
ØSupport for unicode and non latin languag



Demo


•Project Structure

• 1. Create a Dynamic Web project in WSAD

• 2. In WEB-INF/lib place all jar files mentioned.

• 3. Create a folder called report under WEB-INF place all “.jrxml” files

• 4. Create a HelloWorld.jrxml

• 5. Create a Servlet HelloWorld.java



HelloWorld.jrxml















HelloWorld.java (Servlet)

public void doPost(….)..{
context = getServletContext();
HashMap parameter = new HashMap();
parameter.put("Title", "Debtor Bank Commission Report.. ");

try {
jasperReport =JasperCompileManager.compileReport(
context.getRealPath(“
/WEB-INF/report/MinCommissionBankReport.jrxml"));
jasperPrint = JasperFillManager.fillReport(jasperReport,
parameter, ConnectionDb.getConnection() );
// To generate HTML output
createReport(request,response,jasperPrint );
} catch (Exception e) {
e.printStackTrace();}
}
private void createReport(..)throws ServletException, IOException{
JRHtmlExporter exporter = null;
try {
response.setContentType("text/html");
exporter = new JRHtmlExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRHtmlExporterParameter.
IS_USING_IMAGES_TO_ALIGN, Boolean.FALSE);
exporter.setParameter(JRExporterParameter.OUTPUT_WRITER, response.getWriter());
exporter.exportReport();
} catch (RuntimeException e) {throw e; }
catch (Exception e) {
System.out.println("1"+e);
}
}

0 comments: