#LyX 1.6.7 created this file. For more info see http://www.lyx.org/
\lyxformat 345
\begin_document
\begin_header
\textclass scrbook
\begin_preamble
\input{preamble.tex}
\end_preamble
\use_default_options false
\language english
\inputencoding utf8
\font_roman lmodern
\font_sans helvet
\font_typewriter courier
\font_default_family default
\font_sc false
\font_osf false
\font_sf_scale 100
\font_tt_scale 100
\graphics default
\float_placement H
\paperfontsize default
\spacing single
\use_hyperref true
\pdf_bookmarks true
\pdf_bookmarksnumbered false
\pdf_bookmarksopen false
\pdf_bookmarksopenlevel 1
\pdf_breaklinks false
\pdf_pdfborder false
\pdf_colorlinks false
\pdf_backref false
\pdf_pdfusetitle true
\papersize letterpaper
\use_geometry false
\use_amsmath 2
\use_esint 1
\cite_engine basic
\use_bibtopic false
\paperorientation portrait
\secnumdepth 3
\tocdepth 3
\paragraph_separation indent
\defskip medskip
\quotes_language english
\papercolumns 1
\papersides 1
\paperpagestyle default
\bullet 0 5 11 -1
\bullet 1 5 24 -1
\bullet 2 0 0 -1
\tracking_changes false
\output_changes false
\author ""
\author ""
\end_header
\begin_body
\begin_layout Standard
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
input{chapter.tex}
\end_layout
\end_inset
\end_layout
\begin_layout Chapter
\begin_inset CommandInset label
LatexCommand label
name "cha:JasperReports-and-Java"
\end_inset
Report Framework Integrations
\end_layout
\begin_layout Standard
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
epigraph{I am learning that if I just go on accepting the framework for
life that others have given me, if I fail to make my own choices, the reason
for my life will be missing.
I will be unable to recognize that which I have the power to change.}{Liv
Johanne Ullmann}
\end_layout
\end_inset
\end_layout
\begin_layout Standard
This chapter presents a report application integration that can be used
within
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjava{}
\end_layout
\end_inset
-based frameworks.
Building a robust and reusable integration for any
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjava{}
\end_layout
\end_inset
-based platform requires a set of classes that abstract implementation details
about the underlying reporting software.
This chapter provides technical implementation details for such an integration.
\end_layout
\begin_layout Standard
In this chapter:
\end_layout
\begin_layout Itemize
\series bold
Overview.
\series default
Description of the problem integrating
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjasperreports{}
\end_layout
\end_inset
.
\end_layout
\begin_layout Itemize
\series bold
Technologies.
\series default
Definition of the technologies involved in the solution.
\end_layout
\begin_layout Itemize
\series bold
Requirements.
\series default
Description of the required features.
\end_layout
\begin_layout Itemize
\series bold
Architecture Diagram.
\series default
Description of the overall solution.
\end_layout
\begin_layout Itemize
\series bold
Component Diagram.
\series default
Description of the components in the solution.
\end_layout
\begin_layout Itemize
\series bold
Design Patterns.
\series default
List of solutions to architectural problems.
\end_layout
\begin_layout Itemize
\series bold
Integration.
\series default
Use the implementation to generate a report.
\end_layout
\begin_layout Itemize
\series bold
Initialization.
\series default
List of steps to obtain a report instance.
\end_layout
\begin_layout Itemize
\series bold
Interfaces
\series default
.
Key abstractions that allow using new implementations.
\end_layout
\begin_layout Itemize
\series bold
Classes.
\series default
List of classes and their responsibilities.
\end_layout
\begin_layout Itemize
\series bold
Automation.
\series default
General description of automating report creation.
\end_layout
\begin_layout Section
Overview
\end_layout
\begin_layout Standard
The problems with existing
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjasperreports{}
\end_layout
\end_inset
integrations for web-based frameworks include:
\end_layout
\begin_layout Itemize
\series bold
Rare.
\series default
Few integrations are available for existing web platforms.
\end_layout
\begin_layout Itemize
\series bold
Simple.
\series default
Integrations must be easily modified for any
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjava{}
\end_layout
\end_inset
-based web platform, including the frameworks listed on the following web
page:
\begin_inset Foot
status collapsed
\begin_layout Plain Layout
Such as Apache Struts, JBoss Seam, Oracle ADF, Play!, Vaadin, and others.
\end_layout
\end_inset
\end_layout
\begin_deeper
\begin_layout Standard
\begin_inset CommandInset href
LatexCommand href
target "http://en.wikipedia.org/wiki/Comparison_of_web_application_frameworks#Java"
\end_inset
\end_layout
\end_deeper
\begin_layout Itemize
\series bold
Hardcoded.
\series default
Integrations on blogs hard-code items (for example, file paths and database
connections).
\end_layout
\begin_layout Itemize
\series bold
Decentralized.
\series default
Downloads and usage instructions lack a central repository.
\end_layout
\begin_layout Itemize
\series bold
Incomplete.
\series default
Integrations cover a fraction of functionality required for a comprehensive
and robust deployment.
\end_layout
\begin_layout Standard
The remaining sections describe an implementation that addresses many of
these issues.
\end_layout
\begin_layout Section
Technologies
\end_layout
\begin_layout Standard
The solution described in this chapter involves the following technologies:
\end_layout
\begin_layout Itemize
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appservlet{}
\end_layout
\end_inset
\end_layout
\begin_layout Itemize
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjsp{}
\end_layout
\end_inset
s
\end_layout
\begin_layout Itemize
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjsf{}
\end_layout
\end_inset
\end_layout
\begin_layout Itemize
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjsf{}
\end_layout
\end_inset
implementations
\end_layout
\begin_layout Itemize
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjsf{}
\end_layout
\end_inset
component libraries
\end_layout
\begin_layout Standard
If you are already familiar with these technologies, skip to
\begin_inset CommandInset ref
LatexCommand vref
reference "sec:Architecture-Diagram"
\end_inset
.
\end_layout
\begin_layout Subsection
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appservlet{}
\end_layout
\end_inset
\end_layout
\begin_layout Standard
The
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjava{}
\end_layout
\end_inset
Servlet framework is an application programming interface (API) that can
respond to requests made by a web browser and respond appropriately.
Servlets are analogous to Common-Gateway Interfaces and allow programmers
to create web pages with dynamic content (often supplied by a database).
The
\family typewriter
HttpServlet
\family default
API, for example, defines methods for typical Hypertext Transport Protocol
(HTTP) requests such as GET and POST.
Servlets are invoked based on Uniform Resource Locator (URL) patterns,
which are configured in either
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
filename{
\backslash
filexmlweb}
\end_layout
\end_inset
or in source code through
\family typewriter
@WebServlet
\family default
annotations.
\begin_inset Foot
status collapsed
\begin_layout Plain Layout
Annotations require
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjava{}
\end_layout
\end_inset
Enterprise Edition version 6 (
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjava{}
\end_layout
\end_inset
EE 6).
\end_layout
\end_inset
\end_layout
\begin_layout Standard
Instances of
\family typewriter
HttpServletRequest
\family default
and
\family typewriter
HttpServletResponse
\family default
provide:
\end_layout
\begin_layout Itemize
functionality to interact with the browser's request; and
\end_layout
\begin_layout Itemize
a mechanism to customize the content returned to the browser (as the response).
\end_layout
\begin_layout Subsection
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjsp{}
\end_layout
\end_inset
s
\end_layout
\begin_layout Standard
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjsp{}
\end_layout
\end_inset
s provide an abstraction layer for writing HTML code through tag libraries
(known as taglibs).
They are analogous to
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
corpmicrosoft{}
\end_layout
\end_inset
's Active Server Pages technology.
Tag libraries are essentially a collection of tags, not unlike HTML elements,
that are coupled to
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjava{}
\end_layout
\end_inset
code that controls how the final document is rendered (as an HTML fragment).
A common tag library is the
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjsp{}
\end_layout
\end_inset
s Standard Tag Library (JSTL).
Also integral to
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjsp{}
\end_layout
\end_inset
functionality is an Expression Language (EL), which is written inside tag
attributes to interact with system data and functionality (such as session
variables and method calls).
\end_layout
\begin_layout Standard
Although
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjsp{}
\end_layout
\end_inset
s technology provides developers with ways to create custom components by
implementing
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjava{}
\end_layout
\end_inset
classes, such implementations are time-consuming and redundant.
\end_layout
\begin_layout Subsection
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjsf{}
\end_layout
\end_inset
\end_layout
\begin_layout Standard
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjsf{}
\end_layout
\end_inset
is a component-based Model-View-Controller (MVC) framework, set up as follows:
\end_layout
\begin_layout Itemize
\series bold
Model.
\series default
A JavaBean with attributes that represent system data.
\end_layout
\begin_layout Itemize
\series bold
View.
\series default
An XHTML page that represents web page components.
\end_layout
\begin_layout Itemize
\series bold
Controller.
\series default
A FacesServlet instance that gathers input, validates input, invokes actions,
and renders the response.
\begin_inset Foot
status collapsed
\begin_layout Plain Layout
FacesServlet is a servlet subclass:
\begin_inset CommandInset href
LatexCommand href
target "http://download.oracle.com/javaee/6/api/javax/faces/webapp/FacesServlet.html"
\end_inset
\end_layout
\end_inset
\end_layout
\begin_layout Subsection
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjsf{}
\end_layout
\end_inset
Implementations
\end_layout
\begin_layout Standard
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjsf{}
\end_layout
\end_inset
implementations are
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjava{}
\end_layout
\end_inset
classes and interfaces developed to the standard
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjsf{}
\end_layout
\end_inset
API Specification.
Such implementations provide standard components to display basic HTML
elements.
\end_layout
\begin_layout Subsection
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjsf{}
\end_layout
\end_inset
Component Libraries
\end_layout
\begin_layout Standard
A
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjsf{}
\end_layout
\end_inset
component library adds extra functionality to a basic
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjsf{}
\end_layout
\end_inset
implementation.
Component libraries can include additional colour schemes, enhanced Ajax
interactions, additional validation features, component generators, and
more.
\end_layout
\begin_layout Standard
Numerous component libraries exist:
\end_layout
\begin_layout Itemize
Popular:
\begin_inset CommandInset href
LatexCommand href
name "Mojarra"
target "http://java.net/projects/mojarra/"
\end_inset
,
\begin_inset CommandInset href
LatexCommand href
name "JBoss RichFaces"
target "http://www.jboss.org/richfaces"
\end_inset
, and
\begin_inset CommandInset href
LatexCommand href
name "ICEfaces"
target "http://www.icefaces.org/"
\end_inset
\end_layout
\begin_layout Itemize
Apache:
\begin_inset CommandInset href
LatexCommand href
name "MyFaces Tobago"
target "http://myfaces.apache.org/tobago"
\end_inset
,
\begin_inset CommandInset href
LatexCommand href
name "MyFaces Tomahawk"
target "http://myfaces.apache.org/tomahawk/"
\end_inset
, and
\begin_inset CommandInset href
LatexCommand href
name "MyFaces Trinidad"
target "http://myfaces.apache.org/trinidad/"
\end_inset
\end_layout
\begin_layout Itemize
Others:
\begin_inset CommandInset href
LatexCommand href
name "DynaFaces"
target "http://swik.net/DynaFaces"
\end_inset
,
\begin_inset CommandInset href
LatexCommand href
name "OpenFaces"
target "http://openfaces.org/"
\end_inset
,
\begin_inset CommandInset href
LatexCommand href
name "PrimeFaces"
target "http://www.primefaces.org/"
\end_inset
, and
\begin_inset CommandInset href
LatexCommand href
name "WebGalileo Faces"
target "http://www.ria-components.org/content/products/wgf/webGalileoFaces.html"
\end_inset
\end_layout
\begin_layout Standard
A review of these component libraries is beyond the scope of this manual,
as is a complete listing of all available libraries.
\end_layout
\begin_layout Section
Requirements
\end_layout
\begin_layout Standard
A roboust
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjasperreports{}
\end_layout
\end_inset
integration must have at least the following technical features:
\end_layout
\begin_layout Itemize
\series bold
Additions.
\series default
Easily add new static reports.
\end_layout
\begin_layout Itemize
\series bold
Inputs.
\series default
Automatically pass form parameters into the report, including:
\end_layout
\begin_deeper
\begin_layout Itemize
Type casting
\end_layout
\begin_layout Itemize
Dates, times, and timestamps
\end_layout
\begin_layout Itemize
Basic
\family typewriter
java.lang
\family default
data types
\end_layout
\begin_layout Itemize
Arrays as
\family typewriter
java.util.List
\family default
instances
\end_layout
\end_deeper
\begin_layout Itemize
\series bold
Paths.
\series default
Automatically determine the fully qualified path to precompiled reports.
\end_layout
\begin_layout Itemize
\series bold
Styles.
\series default
Dictate report title, style, and language.
\end_layout
\begin_layout Itemize
\series bold
Parameters.
\series default
Set the report title, subtitle, and other report-specific details.
\end_layout
\begin_layout Itemize
\series bold
Embed.
\series default
Include the report content within web pages using the following formats:
\end_layout
\begin_deeper
\begin_layout Itemize
PDF files
\end_layout
\begin_layout Itemize
HTML fragments, with hyperlinks
\end_layout
\end_deeper
\begin_layout Itemize
\series bold
Attachments.
\series default
Send reports to the browser as attachments so that the user is prompted
to save the report (with a suitable default file name).
\end_layout
\begin_layout Itemize
\series bold
Formats.
\series default
Control the output file formats offered to users (for example, PDF file,
HTML page, CSV file, or XML document).
\end_layout
\begin_layout Standard
Supporting requirements include:
\end_layout
\begin_layout Itemize
\series bold
Assignment.
\series default
Editing a page reveals what reports are generated from that page.
\end_layout
\begin_layout Itemize
\series bold
Replaceable.
\series default
Swap the reporting tool for another, without significant implementation
changes.
Applications are shielded from any ripple effect caused by changing the
underlying reporting software.
\begin_inset Foot
status collapsed
\begin_layout Plain Layout
Such as BIRT, OpenReports, Pentaho, and even Crystal Reports.
\end_layout
\end_inset
\end_layout
\begin_layout Itemize
\series bold
Extensible.
\series default
Adding new features and changing existing behaviour by extending the existing
classes, rather than changing source code.
\end_layout
\begin_layout Section
\begin_inset CommandInset label
LatexCommand label
name "sec:Architecture-Diagram"
\end_inset
Architecture Diagram
\end_layout
\begin_layout Standard
Minimally, report application integrations require an architecture that
resembles
\begin_inset CommandInset ref
LatexCommand ref
reference "fig:Generic-Integration-Architecture"
\end_inset
.
\end_layout
\begin_layout Standard
\begin_inset Float figure
wide false
sideways false
status collapsed
\begin_layout Plain Layout
\begin_inset Graphics
filename drawings/report-architecture.png
display false
\end_inset
\end_layout
\begin_layout Plain Layout
\begin_inset Caption
\begin_layout Plain Layout
\begin_inset CommandInset label
LatexCommand label
name "fig:Generic-Integration-Architecture"
\end_inset
Generic Integration Architecture
\end_layout
\end_inset
\end_layout
\end_inset
\end_layout
\begin_layout Standard
The elements in
\begin_inset CommandInset ref
LatexCommand ref
reference "fig:Generic-Integration-Architecture"
\end_inset
consist of the following:
\end_layout
\begin_layout Itemize
\series bold
Input.
\series default
The report parameters, which can be further classified:
\end_layout
\begin_deeper
\begin_layout Itemize
\series bold
User.
\series default
Values that control the report query supplied by the end user.
These often change for each report run.
Examples include birth date, minimum salary, temperature range, and employee
identifier.
\end_layout
\begin_layout Itemize
\series bold
Constants.
\series default
Values that are dynamically generated by the system to support the report.
The values change between report runs, less frequently than user inputs.
Examples include logos, dates, calculations prior to report execution,
and values from ancillary systems.
\end_layout
\begin_layout Itemize
\series bold
System.
\series default
Values that vary the report itself.
These do not often change between report runs.
Examples include a report file reference, suggested file name for downloads,
report title, and style template location.
\end_layout
\end_deeper
\begin_layout Itemize
\series bold
Report Template.
\series default
The report to be filled with data from any type of data source supported
by the reporting application.
\end_layout
\begin_layout Itemize
\series bold
Application.
\series default
The software used to create reports.
This could be
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjasperreports{}
\end_layout
\end_inset
, BIRT, or any other report creation software.
\end_layout
\begin_layout Itemize
\series bold
Report.
\series default
The final report in any output format supported by the report application.
\end_layout
\begin_layout Section
\begin_inset CommandInset label
LatexCommand label
name "sec:Component-Diagram"
\end_inset
Component Diagram
\end_layout
\begin_layout Standard
\begin_inset CommandInset ref
LatexCommand ref
reference "fig:Component-Diagram"
\end_inset
shows the different implementation parts described in this chapter.
\end_layout
\begin_layout Standard
\begin_inset Float figure
wide false
sideways false
status collapsed
\begin_layout Plain Layout
\begin_inset Graphics
filename drawings/architecture-components.png
display false
\end_inset
\end_layout
\begin_layout Plain Layout
\begin_inset Caption
\begin_layout Plain Layout
\begin_inset CommandInset label
LatexCommand label
name "fig:Component-Diagram"
\end_inset
Component Diagram
\end_layout
\end_inset
\end_layout
\end_inset
\end_layout
\begin_layout Standard
The top row (
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appapachetomcat{}
\end_layout
\end_inset
,
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjasperreports{}
\end_layout
\end_inset
, and
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
apppostgres{}
\end_layout
\end_inset
) represents one possible combination of software tools used by the Web
Application.
Other combinations are possible (such as Jetty, BIRT, and MySQL).
The objective is to eliminate references to the concrete dependencies in
the Web Application so that the top row tools can be replaced without additiona
l effort.
\end_layout
\begin_layout Standard
The middle row represents an abstraction layer:
\end_layout
\begin_layout Itemize
\series bold
Web Server.
\series default
This component is a servlet-based framework.
\end_layout
\begin_layout Itemize
\series bold
Reporting Interface.
\series default
This component adapts a specific report package to a common interface.
\end_layout
\begin_layout Itemize
\series bold
Data Source.
\series default
This component isolates instructions to acquire a database connection.
\end_layout
\begin_layout Standard
The last row represents how to leverage the abstraction layer:
\end_layout
\begin_layout Itemize
\series bold
Web Application.
\series default
This component provides reporting functionality to users.
\end_layout
\begin_layout Itemize
\series bold
Reporting Package.
\series default
This package implements the Reporting Interface for
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjasperreports{}
\end_layout
\end_inset
, and can be extended to handle other reporting APIs.
\end_layout
\begin_layout Itemize
\series bold
Persistence Package.
\series default
This package provides an API to acquire a database connection.
\end_layout
\begin_layout Standard
Software development with the Reporting and Persistence Packages ensures
that the Web Application is loosely coupled to the concrete software APIs
that realize your architecture.
\end_layout
\begin_layout Section
Design Patterns
\end_layout
\begin_layout Standard
Structural design patterns suited to the architecture described in
\begin_inset CommandInset ref
LatexCommand ref
reference "sec:Architecture-Diagram"
\end_inset
and
\begin_inset CommandInset ref
LatexCommand ref
reference "sec:Component-Diagram"
\end_inset
include the Adapter and Bridge.
These are defined as follows:
\begin_inset Foot
status collapsed
\begin_layout Plain Layout
Erich Gamma and others.
Published by Addison-Wesley, October 1996.
ISBN: 0201633612.
\end_layout
\end_inset
\end_layout
\begin_layout Itemize
\series bold
Adapter.
\series default
Convert the interface of a class into another interface clients expect.
The Adapter pattern lets classes work together that could not otherwise
due to incompatible interfaces.
\end_layout
\begin_layout Itemize
\series bold
Bridge.
\series default
Decouple an abstraction from its implementation so that the two can vary
independently.
\end_layout
\begin_layout Standard
The Adapter pattern is useful to present a single consistent interface for
different APIs.
For example,
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjasperreports{}
\end_layout
\end_inset
and BIRT have two different sets of classes and methods that are used to
create a PDF file; the Web Application must be shielded from differences
between those two reporting APIs.
The Bridge pattern is useful to avoid a tight coupling between a layer
of abstraction and its concrete implementation.
For example, it aught to be possible to swap
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjasperreports{}
\end_layout
\end_inset
for any other reporting package (
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjava{}
\end_layout
\end_inset
-based or otherwise).
\begin_inset Foot
status collapsed
\begin_layout Plain Layout
Such as BIRT, ReportMill 12, JReport, Windward, or others.
\end_layout
\end_inset
\end_layout
\begin_layout Section
Integration
\end_layout
\begin_layout Standard
A simple integration provides a starting point for the implementation.
\begin_inset CommandInset ref
LatexCommand ref
reference "alg:City-Report-XHTML"
\end_inset
shows a form that renders a minimal web page.
Using
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
apprichfaces{}
\end_layout
\end_inset
is incidental; the form could be written using nearly any component library
or development framework.
\end_layout
\begin_layout Standard
\begin_inset Float algorithm
wide false
sideways false
status collapsed
\begin_layout Plain Layout
\begin_inset Graphics
filename source/xhtml/city.xhtml.png
display false
\end_inset
\end_layout
\begin_layout Plain Layout
\begin_inset Caption
\begin_layout Plain Layout
\begin_inset CommandInset label
LatexCommand label
name "alg:City-Report-XHTML"
\end_inset
City Report XHTML
\end_layout
\end_inset
\end_layout
\end_inset
\end_layout
\begin_layout Standard
\begin_inset CommandInset ref
LatexCommand ref
reference "fig:City-Report-Page"
\end_inset
shows the resulting form rendered by the source code in
\begin_inset CommandInset ref
LatexCommand ref
reference "alg:City-Report-XHTML"
\end_inset
.
\end_layout
\begin_layout Standard
\begin_inset Float figure
wide false
sideways false
status collapsed
\begin_layout Plain Layout
\begin_inset Graphics
filename captures/city-report-form.png
display false
\end_inset
\end_layout
\begin_layout Plain Layout
\begin_inset Caption
\begin_layout Plain Layout
\begin_inset CommandInset label
LatexCommand label
name "fig:City-Report-Page"
\end_inset
City Report Page
\end_layout
\end_inset
\end_layout
\end_inset
\end_layout
\begin_layout Standard
Recall that
\begin_inset CommandInset ref
LatexCommand ref
reference "fig:Generic-Integration-Architecture"
\end_inset
shows inputs, a report template, an application, and a final report.
Almost all of these elements are referenced in
\begin_inset CommandInset ref
LatexCommand ref
reference "alg:City-Report-XHTML"
\end_inset
.
Consider the following lines:
\end_layout
\begin_layout Itemize
\series bold
Line 12.
\series default
This line defines a system parameter (
\family typewriter
system_REPORT_RESOURCE
\family default
) that specifies the report template; this is the report to run.
For
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjasperreports{}
\end_layout
\end_inset
the value is part of the file name without an extension.
For security reasons, the values in
\begin_inset CommandInset ref
LatexCommand vref
reference "tab:Report-Parameter-Values"
\end_inset
(such as
\family typewriter
ROOT_DIR
\family default
) must not be included as hidden form parameters or as the
\family typewriter
system_REPORT_RESOURCE
\family default
value; instead, include the value in a database table or a properties file.
\end_layout
\begin_layout Itemize
\series bold
Line 13.
\series default
This line suggests a file name to use when the user is prompted to save
the report.
\end_layout
\begin_layout Itemize
\series bold
Line 14.
\series default
This line defines a constant parameter.
If the
\family typewriter
report_REPORT_TITLE
\family default
is defined programmatically (for example, by calling a JavaBean method,
which itself is populated from a data source), then it is possible to change
the title for any report at run-time.
The value as shown is hard-coded.
At the very least, change the text string to use a resource bundle value.
\end_layout
\begin_layout Itemize
\series bold
Line 18.
\series default
This line defines a user-supplied parameter.
By default, report variables are treated as character strings (that is,
\family typewriter
java.lang.String
\family default
instances).
No type conversion is performed and the values are passed into the report
verbatim.
\end_layout
\begin_layout Itemize
\series bold
Lines 20 and 22.
\series default
These lines also define user-supplied parameters.
The variable names include a data type prefix.
For example, a
\family typewriter
report_int_
\family default
prefix indicates that the value is converted to an integer type (that is,
\family typewriter
java.lang.Integer
\family default
) before it is passed to the report.
See
\begin_inset CommandInset ref
LatexCommand ref
reference "tab:Variable-Prefix-Map"
\end_inset
for a list of report prefixes.
\end_layout
\begin_layout Itemize
\series bold
Line 24.
\series default
This line executes the report (after the Report button in
\begin_inset CommandInset ref
LatexCommand ref
reference "fig:City-Report-Page"
\end_inset
is clicked).
\end_layout
\begin_layout Standard
Notice the distinct parameter prefixes of
\family typewriter
system_
\family default
and
\family typewriter
report_
\family default
.
This convention allows the Reporting Package (see
\begin_inset CommandInset ref
LatexCommand vref
reference "fig:Component-Diagram"
\end_inset
) to identify variables marked as report parameters.
The
\family typewriter
report_
\family default
parameters are passed into the report automatically (with the prefix removed).
\end_layout
\begin_layout Subsection
System Variables
\end_layout
\begin_layout Standard
\begin_inset CommandInset ref
LatexCommand ref
reference "tab:System-Variable-Map"
\end_inset
lists conventions for mapping system variables that control report behaviours.
\end_layout
\begin_layout Standard
\begin_inset Float table
placement H
wide false
sideways false
status collapsed
\begin_layout Plain Layout
\begin_inset Caption
\begin_layout Plain Layout
\begin_inset CommandInset label
LatexCommand label
name "tab:System-Variable-Map"
\end_inset
System Variable Map
\end_layout
\end_inset
\begin_inset Tabular
<lyxtabular version="3" rows="6" columns="2">
<features>
<column alignment="left" valignment="top" width="0">
<column alignment="left" valignment="top" width="0">
<row>
<cell alignment="left" valignment="top" usebox="none">
\begin_inset Text
\begin_layout Plain Layout
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
rowcolor{tableheader}
\backslash
toprule{}
\end_layout
\end_inset
\series bold
Prefix
\end_layout
\end_inset
</cell>
<cell alignment="left" valignment="top" usebox="none">
\begin_inset Text
\begin_layout Plain Layout
\series bold
Description
\end_layout
\end_inset
</cell>
</row>
<row>
<cell alignment="left" valignment="top" usebox="none">
\begin_inset Text
\begin_layout Plain Layout
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
midrule{}
\end_layout
\end_inset
\family typewriter
system_REPORT_DOWNLOAD
\end_layout
\end_inset
</cell>
<cell alignment="left" valignment="top" usebox="none">
\begin_inset Text
\begin_layout Plain Layout
Prompt users to download the report.
\end_layout
\end_inset
</cell>
</row>
<row>
<cell alignment="center" valignment="top" usebox="none">
\begin_inset Text
\begin_layout Plain Layout
\family typewriter
system_REPORT_ENCODING
\end_layout
\end_inset
</cell>
<cell alignment="center" valignment="top" usebox="none">
\begin_inset Text
\begin_layout Plain Layout
Report character encoding, such as UTF-8.
\end_layout
\end_inset
</cell>
</row>
<row>
<cell alignment="center" valignment="top" usebox="none">
\begin_inset Text
\begin_layout Plain Layout
\family typewriter
system_REPORT_FILENAME
\end_layout
\end_inset
</cell>
<cell alignment="center" valignment="top" usebox="none">
\begin_inset Text
\begin_layout Plain Layout
Suggested filename without extension.
\end_layout
\end_inset
</cell>
</row>
<row>
<cell alignment="center" valignment="top" usebox="none">
\begin_inset Text
\begin_layout Plain Layout
\family typewriter
system_REPORT_FORMAT
\end_layout
\end_inset
</cell>
<cell alignment="center" valignment="top" usebox="none">
\begin_inset Text
\begin_layout Plain Layout
Report type to generate, such as PDF.
\end_layout
\end_inset
</cell>
</row>
<row>
<cell alignment="center" valignment="top" usebox="none">
\begin_inset Text
\begin_layout Plain Layout
\family typewriter
system_REPORT_RESOURCE
\end_layout
\end_inset
</cell>
<cell alignment="center" valignment="top" usebox="none">
\begin_inset Text
\begin_layout Plain Layout
Uniquely identifies the report template.
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
tabularnewline
\backslash
bottomrule%
\end_layout
\end_inset
\end_layout
\end_inset
</cell>
</row>
</lyxtabular>
\end_inset
\end_layout
\end_inset
\end_layout
\begin_layout Standard
These variables are defined independently of all reporting software.
\end_layout
\begin_layout Subsection
Report Variable Prefixes
\end_layout
\begin_layout Standard
\begin_inset CommandInset ref
LatexCommand ref
reference "tab:Variable-Prefix-Map"
\end_inset
lists conventions for mapping input parameters to
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjava{}
\end_layout
\end_inset
classes.
\end_layout
\begin_layout Standard
\begin_inset Float table
placement H
wide false
sideways false
status collapsed
\begin_layout Plain Layout
\begin_inset Caption
\begin_layout Plain Layout
\begin_inset CommandInset label
LatexCommand label
name "tab:Variable-Prefix-Map"
\end_inset
Variable Prefix Map
\end_layout
\end_inset
\begin_inset Tabular
<lyxtabular version="3" rows="8" columns="2">
<features>
<column alignment="left" valignment="top" width="0">
<column alignment="left" valignment="top" width="0">
<row>
<cell alignment="left" valignment="top" usebox="none">
\begin_inset Text
\begin_layout Plain Layout
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
rowcolor{tableheader}
\backslash
toprule{}
\end_layout
\end_inset
\series bold
Prefix
\end_layout
\end_inset
</cell>
<cell alignment="left" valignment="top" usebox="none">
\begin_inset Text
\begin_layout Plain Layout
\series bold
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjava{}
\end_layout
\end_inset
Class
\end_layout
\end_inset
</cell>
</row>
<row>
<cell alignment="left" valignment="top" usebox="none">
\begin_inset Text
\begin_layout Plain Layout
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
midrule{}
\end_layout
\end_inset
\family typewriter
report_
\end_layout
\end_inset
</cell>
<cell alignment="left" valignment="top" usebox="none">
\begin_inset Text
\begin_layout Plain Layout
\family typewriter
java.lang.String
\end_layout
\end_inset
</cell>
</row>
<row>
<cell alignment="left" valignment="top" usebox="none">
\begin_inset Text
\begin_layout Plain Layout
\family typewriter
report_int_
\end_layout
\end_inset
</cell>
<cell alignment="left" valignment="top" usebox="none">
\begin_inset Text
\begin_layout Plain Layout
\family typewriter
java.lang.Integer
\end_layout
\end_inset
</cell>
</row>
<row>
<cell alignment="left" valignment="top" usebox="none">
\begin_inset Text
\begin_layout Plain Layout
\family typewriter
report_float_
\end_layout
\end_inset
</cell>
<cell alignment="left" valignment="top" usebox="none">
\begin_inset Text
\begin_layout Plain Layout
\family typewriter
java.lang.BigDecimal
\end_layout
\end_inset
</cell>
</row>
<row>
<cell alignment="center" valignment="top" usebox="none">
\begin_inset Text
\begin_layout Plain Layout
\family typewriter
report_array_int_
\end_layout
\end_inset
</cell>
<cell alignment="center" valignment="top" usebox="none">
\begin_inset Text
\begin_layout Plain Layout
\family typewriter
java.util.List
\end_layout
\end_inset
</cell>
</row>
<row>
<cell alignment="center" valignment="top" usebox="none">
\begin_inset Text
\begin_layout Plain Layout
\family typewriter
report_date_
\end_layout
\end_inset
</cell>
<cell alignment="center" valignment="top" usebox="none">
\begin_inset Text
\begin_layout Plain Layout
\family typewriter
java.util.Date
\end_layout
\end_inset
</cell>
</row>
<row>
<cell alignment="center" valignment="top" usebox="none">
\begin_inset Text
\begin_layout Plain Layout
\family typewriter
report_time_
\end_layout
\end_inset
</cell>
<cell alignment="center" valignment="top" usebox="none">
\begin_inset Text
\begin_layout Plain Layout
\family typewriter
java.sql.Time
\end_layout
\end_inset
</cell>
</row>
<row>
<cell alignment="center" valignment="top" usebox="none">
\begin_inset Text
\begin_layout Plain Layout
\family typewriter
report_timestamp_
\end_layout
\end_inset
</cell>
<cell alignment="center" valignment="top" usebox="none">
\begin_inset Text
\begin_layout Plain Layout
\family typewriter
java.sql.Timestamp
\family default
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
tabularnewline
\backslash
bottomrule%
\end_layout
\end_inset
\end_layout
\end_inset
</cell>
</row>
</lyxtabular>
\end_inset
\end_layout
\end_inset
\end_layout
\begin_layout Standard
These prefixes are defined independently of all reporting software.
Even though the converted types are influenced by
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjasperreports{}
\end_layout
\end_inset
parameter data types, the reporting architecture provides a facility to
change the concrete conversion type as required by the reporting software.
\end_layout
\begin_layout Subsection
Security Risk
\end_layout
\begin_layout Standard
All input values must be sanitized.
This is especially critical when using terms such as ``system'' to denote
how variables are used.
It is easy for people to guess that system parameters are used by the system
in some fashion.
So, restrict system variables to alphanumeric character sets.
\end_layout
\begin_layout Subsection
\begin_inset CommandInset label
LatexCommand label
name "sub:Faces-Configuration"
\end_inset
Faces Configuration
\end_layout
\begin_layout Standard
Update the faces configuration as follows:
\end_layout
\begin_layout Enumerate
Edit
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
filename{
\backslash
filexmlfaces}
\end_layout
\end_inset
.
\end_layout
\begin_layout Enumerate
Add a managed bean using the following code:
\end_layout
\begin_deeper
\begin_layout LyX-Code
\size small
<managed-bean>
\end_layout
\begin_layout LyX-Code
\size small
<managed-bean-name>report</managed-bean-name>
\end_layout
\begin_layout LyX-Code
\size small
<managed-bean-class>
\end_layout
\begin_layout LyX-Code
\size small
com.whitemagicsoftware.report.bean.ReportBean
\end_layout
\begin_layout LyX-Code
\size small
</managed-bean-class>
\end_layout
\begin_layout LyX-Code
\size small
<managed-bean-scope>request</managed-bean-scope>
\end_layout
\begin_layout LyX-Code
\size small
</managed-bean>
\end_layout
\end_deeper
\begin_layout Standard
The web application is configured.
\end_layout
\begin_layout Section
Initialization
\end_layout
\begin_layout Standard
To create a report without specific reporting tool dependencies involves
the following steps:
\end_layout
\begin_layout Enumerate
\series bold
Main.
\series default
Create the system entry point.
For example, this is accomplished in
\begin_inset CommandInset ref
LatexCommand ref
reference "sub:Faces-Configuration"
\end_inset
.
\end_layout
\begin_layout Enumerate
\series bold
Report Factory.
\series default
Create a class that hides knowledge of how reports are created.
As reports are created using a Report Creator, this class can be considered
a report factory factory.
For example, the
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjasperreports{}
\end_layout
\end_inset
API offers serveral report types,
\begin_inset Foot
status collapsed
\begin_layout Plain Layout
Such as PDF, CSV, XML, HTML, and others.
\end_layout
\end_inset
each is represented by a corresponding class.
\end_layout
\begin_layout Enumerate
\series bold
Report Creator.
\series default
Create a class that can instantiate the appropriate class given a specific
report type.
Report Creators are tightly coupled to a specific reporting tool implementation.
\end_layout
\begin_layout Enumerate
\series bold
Controller Factory.
\series default
Create a class that hides knowledge of how controllers are created.
For example, if the software development architecture is
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appservlet{}
\end_layout
\end_inset
-based, then the factory will create a controller that can read parameters,
write to streams using the
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appservlet{}
\end_layout
\end_inset
API, and set the fully qualified directory path in which reports are saved.
\end_layout
\begin_layout Enumerate
\series bold
Parameters Factory.
\series default
Create a class that hides knowledge of how parameters are converted from
user inputs (provided by the controller, which may or may not be strongly
typed) to strongly typed report-specific parameters.
\end_layout
\begin_layout Enumerate
\series bold
Report.
\series default
Create a class that can execute a report.
The reason why the previous steps are necessary is summarized by the following
requirements chain:
\end_layout
\begin_deeper
\begin_layout Enumerate
The report requires a report type.
\end_layout
\begin_layout Enumerate
The report type requires an input parameter.
\end_layout
\begin_layout Enumerate
The input parameters must be populated by the controller.
\end_layout
\begin_layout Enumerate
The controller integrates with an application framework.
\end_layout
\end_deeper
\begin_layout Standard
The sequence diagram in
\begin_inset CommandInset ref
LatexCommand ref
reference "fig:Report-Creation-Sequence"
\end_inset
depicts the initial steps to create a report based on the steps given above.
Creating the data source connection depends on a variety of factors.
The implementation provided with this manual uses
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjava{}
\end_layout
\end_inset
's Naming and Directory Interface (JNDI) to acquire a database connection.
\end_layout
\begin_layout Standard
This dependency injection problem can also be resolved using
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appspring{}
\end_layout
\end_inset
.
\begin_inset Foot
status collapsed
\begin_layout Plain Layout
\begin_inset CommandInset href
LatexCommand href
name "http://www.springsource.org/"
target "http://www.springsource.org/"
\end_inset
\end_layout
\end_inset
\end_layout
\begin_layout Standard
\begin_inset Float figure
wide false
sideways false
status collapsed
\begin_layout Plain Layout
\begin_inset Graphics
filename drawings/report-sequence-01.png
display false
\end_inset
\end_layout
\begin_layout Plain Layout
\begin_inset Caption
\begin_layout Plain Layout
\begin_inset CommandInset label
LatexCommand label
name "fig:Report-Creation-Sequence"
\end_inset
Report Creation Sequence
\end_layout
\end_inset
\end_layout
\end_inset
\end_layout
\begin_layout Section
\begin_inset CommandInset label
LatexCommand label
name "sec:Interfaces"
\end_inset
Interfaces
\end_layout
\begin_layout Standard
Interfaces isolate knowledge of how reports are generated from your application.
This is accomplished by defining the following interfaces:
\end_layout
\begin_layout Itemize
\series bold
Report.
\series default
The
\family typewriter
Report
\family default
's
\family typewriter
run()
\family default
method defines how to execute the report.
For example, after a JavaBean calls the ReportFactory to create a
\family typewriter
Report
\family default
instance, the
\family typewriter
run()
\family default
method is called to export the report.
\end_layout
\begin_layout Itemize
\series bold
Controller.
\series default
The
\family typewriter
Controller
\family default
interface requires implementations to coordinate communications between
the
\family typewriter
Report
\family default
and its
\family typewriter
Parameters
\family default
.
The
\family typewriter
Controller
\family default
interfaces also defines a
\family typewriter
java.io.OutputStream
\family default
that mandates where the report content is written.
\end_layout
\begin_layout Itemize
\series bold
Parameters.
\series default
The
\family typewriter
Parameters
\family default
interface requires concrete implementations adapt their mechanism for passing
parameters into reports.
Implementations are also responsible for parsing user input values and
converting them into data types expected by the reporting software API.
\end_layout
\begin_layout Section
Classes
\end_layout
\begin_layout Standard
When developing classes that implement the interfaces defined in
\begin_inset CommandInset ref
LatexCommand ref
reference "sec:Interfaces"
\end_inset
, there is potential for duplication.
This section describes the facilities that help avoid duplication, provide
an example implementation, and improve system stability.
\end_layout
\begin_layout Subsection
Abstract
\end_layout
\begin_layout Standard
Noteworthy (or essential) abstract classes include:
\end_layout
\begin_layout Itemize
\series bold
AbstractReport.
\series default
Contains references to the
\family typewriter
Controller
\family default
and the
\family typewriter
Parameters
\family default
interface implementations.
The report's character encoding is defined in this class by extracting
the designated report parameter.
\end_layout
\begin_layout Itemize
\series bold
AbstractController.
\series default
This class provides convenience methods that help reduce duplication for
specific architectures.
\end_layout
\begin_layout Itemize
\series bold
AbstractParameters.
\series default
Defines an abstract method called
\family typewriter
coerce(...)
\family default
that subclasses implement to convert input parameters to the specific data
types expected by the report's parameters.
\end_layout
\begin_layout Itemize
\series bold
AbstractReportBean.
\series default
For systems that use managed beans (also known as backing beans), this
class can be considered the main entry point.
It is possible to replace this class with
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appspring{}
\end_layout
\end_inset
-based dependency injection.
For applications that do not use
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appspring{}
\end_layout
\end_inset
(or any other dependency injection framework), this class serves as an
example of how to generate a report.
\end_layout
\begin_layout Subsection
Concrete
\end_layout
\begin_layout Standard
The important concrete classes that implement the requisite functionality,
and serve as an example, include:
\end_layout
\begin_layout Itemize
\series bold
ReportCreatorImpl.
\series default
Creates a report based on a given report type.
For example, given a PDF report type, the
\family typewriter
getInstance(...)
\family default
method of this class will return a
\family typewriter
PDFReportImpl
\family default
instance.
\end_layout
\begin_layout Itemize
\series bold
ReportImpl.
\series default
Makes extensive use of the
\family typewriter
Controller
\family default
to configure the
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjasperreports{}
\end_layout
\end_inset
environment when generating the report.
The entry point---the
\family typewriter
run()
\family default
method---requests all necessary pre- and post-processing before and after
the report is generated, respectively.
This is the superclass to all
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjasperreports{}
\end_layout
\end_inset
-specific report format implementations.
\end_layout
\begin_layout Itemize
\series bold
JSFControllerImpl.
\series default
Interacts with
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjsf{}
\end_layout
\end_inset
to set HTTP response headers and publish exception messages.
This controller class determines whether or not the report should be embedded
into the web page content or downloaded separately.
\end_layout
\begin_layout Itemize
\series bold
ParametersImpl.
\series default
Converts input parameters to the data types expected by the
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjasperreports{}
\end_layout
\end_inset
API, as defined in
\begin_inset CommandInset ref
LatexCommand ref
reference "tab:Variable-Prefix-Map"
\end_inset
.
This class also removes the entire
\family typewriter
report_
\family default
prefix so that the names are passed into the report as expected.
The
\family typewriter
AbstractParameters
\family default
class defines the looping mechanism that iterates over all the input variables,
calling the abstract
\family typewriter
coerce(...)
\family default
method on each input parameter.
\end_layout
\begin_layout Subsection
Exception
\end_layout
\begin_layout Standard
Where feasible, the methods in this implementation do not return
\family typewriter
null
\family default
values.
\begin_inset Foot
status collapsed
\begin_layout Plain Layout
Over forty years after he invented it, Tony Hoare called the
\family typewriter
null
\family default
reference a ``billion-dollar mistake.'' The number of
\family typewriter
NullPointerException
\family default
errors that occur in
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjava{}
\end_layout
\end_inset
programs supports his remark.
\end_layout
\end_inset
Instead, this implementation favours throwing exceptions for erroneous
conditions and providing default values whenever possible.
When generating the report, all exceptions are trapped and published by
the controller implementation.
\end_layout
\begin_layout Standard
The source code for the exceptions is fully documented; for more information
about what exceptions are thrown and how they are used, read the Javadocs.
\end_layout
\begin_layout Section
Automation
\end_layout
\begin_layout Standard
Strictly speaking, lines 12 through 24 in
\begin_inset CommandInset ref
LatexCommand vref
reference "alg:City-Report-XHTML"
\end_inset
do not require intervention by computer programmers.
Broadly speaking, integrating reports with web frameworks can be reduced
to the following steps:
\end_layout
\begin_layout Enumerate
Create reports.
With
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjasperreports{}
\end_layout
\end_inset
this entails developing software to automatically generate compiled
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
filename{
\backslash
fileextjasper}
\end_layout
\end_inset
report files.
\begin_inset Foot
status collapsed
\begin_layout Plain Layout
\begin_inset CommandInset href
LatexCommand href
name "DynamicJasper"
target "http://dynamicjasper.com/"
\end_inset
implements a Façade Pattern that simplifies the
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjasperreports{}
\end_layout
\end_inset
API to expedite report development.
\end_layout
\end_inset
\end_layout
\begin_layout Enumerate
Create web pages.
Implement a user interface that allows users to select the data columns
of interest.
The application then generates web pages using a combination of the human-reada
ble text from the data dictionary described in
\begin_inset CommandInset ref
LatexCommand ref
reference "cha:Data-Dictionary"
\end_inset
and the database meta data (to determine the input parameter types).
\end_layout
\begin_layout Standard
Another solution is to use an existing tool, such as
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjasperserver{}
\end_layout
\end_inset
, that allows users to create their own
\emph on
ad hoc
\emph default
reports.
\end_layout
\begin_layout Section
Parameters Revisited
\end_layout
\begin_layout Standard
\begin_inset CommandInset ref
LatexCommand vref
reference "tab:Report-Parameter-Values"
\end_inset
defines a report parameter named
\family typewriter
ROOT_DIR
\family default
.
The value for the
\family typewriter
ROOT_DIR
\family default
parameter must not be exposed in
\begin_inset CommandInset ref
LatexCommand vref
reference "alg:City-Report-XHTML"
\end_inset
.
Instead, the report integration framework must set the
\family typewriter
ROOT_DIR
\family default
value without exposing the value to users.
\end_layout
\begin_layout Standard
Using
\begin_inset ERT
status open
\begin_layout Plain Layout
\backslash
appjsf{}
\end_layout
\end_inset
, one possible solution is to subclass
\family typewriter
JSFControllerImpl
\family default
to override and add functionality to the
\family typewriter
setInputParameters()
\family default
method as follows:
\end_layout
\begin_layout Enumerate
Call the superclass's
\family typewriter
setInputParameters()
\family default
method.
\end_layout
\begin_layout Enumerate
Get the
\family typewriter
Parameters
\family default
instance using the
\family typewriter
getParameters()
\family default
method.
\end_layout
\begin_layout Enumerate
Get the report path using the
\family typewriter
getReportPath()
\family default
method.
\end_layout
\begin_layout Enumerate
Call
\family typewriter
put(...)
\family default
on the parameters using
\family typewriter
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
textquotedbl{}
\end_layout
\end_inset
ROOT_DIR
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
textquotedbl{}
\end_layout
\end_inset
\family default
and the report path.
\end_layout
\begin_layout Enumerate
Configure the
\family typewriter
ControllerFactory
\family default
to use the new subclass.
\end_layout
\begin_layout Standard
The
\family typewriter
ROOT_DIR
\family default
parameter is passed into the reports.
In this example, the path for the report is derived from the web application.
A more secure and flexible approach allows the path to change depending
on the execution environment by requesting the path from the database.
\end_layout
\begin_layout Section
Summary
\end_layout
\begin_layout Standard
Liv Johanne Ullmann, actor and film director, astutely noted that frameworks
created by others are not necessarily appropriate for your situation.
The framework described in this chapter meets many requirements, yet must
be subjected to an impartial evaluation to determine whether it is suitable
for your project.
Finding and using source code in your project that merely gets the job
done does not heed Ullmann's warning; rather, it exacerbates the problem
by duplicating source code that is tightly coupled to an extremely specific
set of tools.
\end_layout
\end_body
\end_document