F. Stoica, Deliver dynamic and interactive Web content in J2EE applications, Proceedings of the Central and East European Conference in Business Information Systems, Cluj-Napoca, Romania, ISBN 973-656-648-X, pp. 780-789, 2004
Deliver Dynamic and Interactive Web Content in J2EE Applications
1. DELIVER DYNAMIC AND INTERACTIVE WEB
CONTENT IN J2EE APPLICATIONS
Florin Stoica
"Lucian Blaga" University of Sibiu, Faculty of Sciences,
Computer Sciences and Economic Informatics Department,
Romania
e-mail: florin.stoica@ulbsibiu.ro
Reporting is the process of accessing data, formatting it, and delivering it as information
inside and outside the organization. It serves as the foundation of broader business
intelligence strategy by providing the most-requested pieces of information reliably and
securely. The advent of the Web has provided yet another medium to distribute information -
and with it developers are faced with a variety of challenges in getting actionable information
into the hands of end users in a consumable format, as quickly as possible. We focus on J2EE
applications because J2EE application servers provide a baseline of functionality that makes it
easy to develop distributed business components, and assemble them into robust and function-
complete business solutions that perform well and are highly scalable.
1. INTRODUCTION
Publishing data to an web site should be quick, requiring minimal code and
providing rich functionality for the end user. It should offer:
• Rich, presentation-quality information with minimal coding.
• Total integration of content into the web site via flexible customization.
• Full interactivity to empower end users to get the exact information they
require by viewing current reports, modifying reports, scheduling new
ones, using parameterized reports, and exporting to a variety of formats.
In this paper, we discuss our experience with integrating Business Objects reporting
products with Sun J2EE Application Server 1.4 Developer Release. These products
include:
• Crystal Reports - an intuitive reporting toolkit for creating flexible,
feature-rich reports and tightly integrate them into web (and windows)
applications.
• Crystal Report Application Server - a common architecture for data
access, reporting, and information delivery in a dynamic manner with
interactive suport.
The goal of this paper is to help others evaluate the benefits of using Crystal Report
Application Server in the context of a J2EE application.
2. 2. JSP vs. CRYSTAL REPORT
Java Server Pages is one of the most popular technologies for publishing interactive
content, primarily because it is:
• Familiar – JSP technology have been widely adopted by the Java
community.
• A standard – JSP is a specification, not a product. Because many vendors
are competing to provide tools for JSP developers, it is more likely that
the standard will endure.
• An effective division of labor - JSP technology provides a separation
between markup language and programming language code. Typically,
page authors define the user experience using markup language. Java
developers develop Servlets to handle input processing, and EJB’s to
define the business logic.
Using Crystal technology offers all of the benefits of JSP at a fraction of the time
and cost:
• Presentation-quality, interactive reporting – Work within an intuitive
object-oriented designer interface to create reports as interactive
documents with drilldown, charts, maps, alerting, parameter prompts,
hyperlinks, personalization and much more. Report designer supports the
creation of virtually any report, style or format required: a cross tab,
invoice, order form, etc. Formatting using fonts, lines, graphics and free-
form layouts is available at the click of a button or wizard using Crystal.
• Leverage familiar standards – Leveraging common web standards,
including DHTML, XML, JDBC and EJB’s, Crystal technology
complete control over all aspects of content generation, integration and
systemfunctionality.
• Fully customizable – Powerful customization features and full support
for standard scripting languages allows developers to rapidly build
tailored web applications.
• Virtually no code required – With the ability to manipulate data into
groups, summarize it, sort and filter, developers can focus on more
difficult project components, such as business logic.
• Parameterized reporting to more complex sorting, filtering, summarizing,
maps and charting.
• Built-in navigation tools including table of content, hyperlinks, drill
down and searching.
• Exports to Adobe Acrobat (PDF), Microsoft Excel and Word (RTF) and
native Crystal Reports format.
Publishing data using JSPs is typically accomplished by hand-coding the static and
dynamic content. In many ways, a “complex” report that includes the above
3. functionality becomes an application in its own right. This approach can became
problematic for a number of reasons:
• The implementation effort for reports with grouped data proved to be
prohibitive.
• We had no practical way to rapidly prototype reports.
• Maintenance became very time-consuming.
• Customization of the output of the reports for specific uses (e.g. printing,
exports) is time-consuming (or almost impossible).
Crystal also includes page-on-demand report processing technology. It breaks down
each report into individual pages, sending the requested individual pages - and not
the entire report - down to the browser. Page-on-demand also supports job sharing:
reports are cached and the above individual pages can be resent instead of hitting
database again to regenerate data. This technology minimize the number of queries
to the underlying database resulting in ď€ higher performance for the end user, less
bandwidth and less hardware costs.
3. REPORT APPLICATION SERVER ARCHITECTURE
This section describes the Report Application Server (RAS) components. The RAS
is in itself a client/server systemand is composed of two basic components: the RAS
server, and an SDK that provides an interface to the server (figure 3.1). The web
container manages communication between the web browser and the RAS SDK.
Fig. 3.1 Report Application Server basic components
The RAS server provides the services for building and customizing reports. In this
sense, it forms the server part of the client/server system. The server handles report
documents using the Crystal Reports Print Engine (CRPE).
The RAS SDK is composed of a number of Java packages, which contain interfaces
and classes for communicating with the server. Essentially, the packages divide the
interfaces and classes into functional areas. The RAS SDK is the client part of the
Web Browser
Web Container
RAS SDK
RAS Server
4. client/server system. and is implemented using a Model-View-Controller
architecture.
The following diagram presents a high-level view of the packages and some key
controllers in the RAS Java SDK. This diagram represents controllers, object
models, and the view component.
Fig. 3.2 RAS Java SDK Architecture
The object models are used to define the content in a report document. They contain
the data structures necessary to determine the view of the objects in the report
document. The object models are implemented in two main libraries:
• The data package provides a definition for the report’s database and data.
• The definition package determines the appearance and layout of the
report objects that appear in a report document.
The controllers are defined in the application package. They possess the logic to
modify the object models on the client side. Although the object models provide
functionality to manipulate the data and report definition, they do not synchronize
the data that client is manipulating with that on the server. In order to properly
modify a report document and ensure that the RAS server is updated, must be used
the appropriate controller.
ReportClientDocument
ReportClientDocument
Modify data in the model and update RAS Server
(a report document)
Controllers (application package)
DatabaseController
DataDefController
ReportDefController
RowsetController
Model (core functional areas) Other packages
data package
definition package
document lib
exportoptions
View
(Report
Viewer)
View
selection
Query /
Modify
a report
document
5. The client documents are the report documents that the RAS SDK creates and
modifies. These report documents are managed by the the ReportClientDocument
object which controls the way that report documents are handled. It is the central
point from which all other libraries in the SDK derive, and it enables accessing
either the controllers (to modify or extract data), or the object models (to access
data). Effectively, it allows to open, modify, and save reports.
Finally, the view, provides a particular view of the data in the model. Each view
may access the data in the model directly or by using a controller. In order to modify
data the model, it is necessary to use a controller. There are three thin client
DHTML Report Viewers:
1. Crystal Reports Viewer (provides basic web reporting viewer capabilities).
2. Crystal Reports Interactive Viewer (provides all the capabilities of the Java
Report Page Viewer, plus the ability to do a Boolean search on the current
report).
3. Crystal Reports Parts Viewer (provides the ability to view individual report
parts - charts, text, or fields).
4. WEB REPORTING USING RAS SDK
This section provides some sample examples of how to use some of the basic
functionality of the RAS SDK to display a report, modify data definition (a formula
field) and change data source at runtime.
Example 4.1: View a report using Crystal Reports Interactive Viewer (complete
code).
<%@ page import="com.crystaldecisions.sdk.occa.report.application.*,
com.crystaldecisions.sdk.occa.report.data.*,
com.crystaldecisions.sdk.occa.report.lib.*,
com.crystaldecisions.report.web.viewer.*"
%>
<html>
<head>
<title> Simple Preview Report</title>
</head>
<body>
<%
/**
* This line creates a string variable called reportName that we will use to pass
* the Crystal Report filename (.rpt file) to the OpenReport method
*/
6. String reportName ="admit_info.rpt";
// Get the physical path of the application directory
String path = request.getRealPath("/");
// Create a new Report Application Session
ReportAppSession ra = new ReportAppSession();
// Create a Report Application Server Service
ra.createService("com.crystaldecisions.sdk.occa.report.application.
ReportClientDocument");
// Set the RAS Server to be used for the service
ra.setReportAppServer("127.0.0.1");
// Initialize RAS
ra.initialize();
// Create the report client document object
ReportClientDocument clientDoc = new ReportClientDocument();
// Set the RAS Server to be used for the Client Document
clientDoc.setReportAppServer(ra.getReportAppServer() );
// Open the report, and set the open type to Read Only
clientDoc.open(path + reportName, OpenReportOptions._openAsReadOnly);
// Create an Interactive Viewer
CrystalReportInteractiveViewer viewer = new CrystalReportInteractiveViewer();
// Set the name for the interactive viewer
viewer.setName("Crystal_Report_Interactive_Viewer");
// Custom options
viewer.setOwnPage(true);
viewer.setHasPrintButton(true);
viewer.setHasExportButton(true);
viewer.setHasToggleGroupTreeButton(false);
viewer.setDisplayGroupTree(false);
// Set the source for the interacive viewer to the client documents report source
viewer.setReportSource(clientDoc.getReportSource());
// Process the http request to view the report
viewer.processHttpRequest(request,response,
getServletConfig().getServletContext(), out);
// Dispose of the viewer object
viewer.dispose();
%>
</body>
</html>
7. Example 4.2: Change a formula definition at runtime (partial code).
<%
//Working with the formula fields collection
// Get the formula from the report through the Data Definition Controller
Fields fieldsCollection =
clientDoc.getDataDefController().getDataDefinition().getFormulaFields();
// Make a temporary copy of the formula field to be modified
FormulaField tempFormula = new FormulaField();
// Retrieve the first field from the formula field collection
Field temp = (Field)fieldsCollection.getField(0);
// Copy the field attributes to the temporary formula field
temp.copyTo(tempFormula, false);
// Set the new formula text to the temporary formula object
tempFormula.setText("{Product.Price} * 1.19");
// Modify the formula through the FormulaFieldController
clientDoc.getDataDefController().getFormulaFieldController().
modify(0,tempFormula);
%>
Fig. 4.1 Object ModelDiagram for example 4.2 (change a formula definition)
Example 4.3: Change a data source at runtime (partial code).
<%
// Create the jdbc-odbc bridge and retrieve a ResultSet
// Create class for JDBC:ODBC bridge
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
// Construct connection
java.sql.Connection connection = DriverManager.getConnection(
"jdbc:odbc:MyDatabase","Admin", "");
ClientDocument
ReportClientDocument
getDataDefController() DataDefController
getDataDefinition() IDataDefinition
FormulaFieldControllergetFormulaFieldController()
8. // Construct statement
Statement statement = connection.createStatement();
// Construct result set through query
ResultSet results = statement.executeQuery("Select * from Product");
//Pass the ResultSet to the report through the Database Controller
// Set the datasource for the report to the java.sql.ResultSet through the Database
// Controller
clientDoc.getDatabaseController().setDataSource(results,
clientDoc.getDatabase().getTables().getTable(0).getName(), "Reports");
%>
Fig. 4.2 Object ModelDiagram for example 4.3 (change data source)
5. INTEGRATION WITH SUN J2EE APPLICATION SERVER 1.4
In order to make RAS SDK packages available to J2EE Server, we must copy all jar
archives from <drive>:Program FilesCommon FilesCrystal Decisions2.0jars
(where <drive> denote partition where Crystal RAS was installed) to a subdirectory
(for example: jars) of directory where J2EE Server was installed. After that, we add
all these packages in JVM Settings -> Path Settings including -> Classpath Suffix.
Next step is to modify security.policy of default domain, for allowing RAS to acces
report documents from deployed applications. In this file must be added (for
example):
grant codebase "file:${com.sun.enterprise.home}/jars/-" {
permission java.security.AllPermission;
};
Next step, in RAS Configuration Manager must specify Report Directory as
<j2ee_home>domainsdomain1applicationsj2ee-apps, where <j2ee_home> is
directory where J2EE Server was installed. The Report Directory setting specifies
which folder the Report Application Server has access to (would allow access to the
specified folder and all sub-folders).
Finally, we must copy the directory:
ClientDocument
ReportClientDocument
getDatabase() IDataBase
getDatabaseController() DatabaseController
9. <drive>:Program FilesCommon FilesCrystal Decisions2.0crystalreportviewers
as
<j2ee_home>domainsdomain1docrootcrystalreportviewers.
The next image presents a report document delivered by Report Application Server
and displayed in Crystal Reports Interactive Viewer:
Fig. 5.1 Report Application Server & CrystalReports Interactive Viewer in action
6. CONCLUSIONS
The combination of the Report Application Server (RAS) and the RAS SDK
provides the ability to easily deliver rich, actionable content on the Java
development platform. Capabilities of the SDK include creating reports on the fly,
opening existing reports, adding and removing sections, fields, charts, and many
other report elements, manipulating report parameters and formulas, and applying
design templates to produce richly formatted reports.
In web-based applications, the SDK resides on the application server, however all
processing is delegated off to the Report Application Server to process. This Server
can reside on the application server, but can also be offloaded to a dedicated report
processing server.
10. The SDK is fully supported for use in Java Server Pages (JSP), Servlets, and
Enterprise Java Beans (EJBs) and provide tight integration with J2EE. There are
also a set of server-side report viewer components included. These interactive
components render the report to pure HTML format, meaning that end users require
nothing more than a standard web browser to view reports. This zero-client delivery
reduces IT headaches by eliminating client-side control installation.
An important benefit provided by Crystal technology is the decoupling of report
design from application development. Often, a developer can delegate report content
design to a business analyst.
Compared to JSP-coded reports, Crystal technology simplifies the entire report
creation and publishing process, and data is delivered to the Web much more faster.
REFERENCES
[1] Bruce Eckel, Thinking in Java, 3rd Edition, Prentice-Hall, 2002
[2] Inderjeet Singh, Beth Stearns, Mark Johnson,Enterprise Team, Designing
Enterprise Applications with the J2EE Platform, Second Edition, Addison-
Wesley, 2002
[3] Bill Sheldon, Crystal Enterprise - A report server solution,
http://www.businessobjects.com/products/dev_zone/default.asp
[4] Business Objects, Enterprise Reporting brochure,
http://www.businessobjects.com/products/reporting/default.asp
[5] Business Objects, Crystal Enterprise datasheet,
http://www.businessobjects.com/products/reporting/default.asp
[6] Ben Forta, Edwin Smith, Roger Kerr, JavaServer Pages, Teora, 2002
[7] Crystal Decisions, Report Application Server Java SDK Guide, 2002