|
We use reports in all aspects of our personal and business lives.
When data is presented in a well organized and informative
manner, such as with business reports, it can significantly
improve our critcal decision making processes. The report
development workflow and MyEclipse Reports tools can be used to
develop a wide range of web report types. In this tutorial we
will walk through the basic workflow for creating, deploying and
testing a simple customer listing web report using the MyEclipse
Reports features.
Figure 1-1 is a screenshot of the completed customer listing
report. You can download the customer listing report project
developed in this tutorial using the Examples On-Demand browser, MyEclipse > Examples On-Demand.
Figure 1-1, Customer listing report from this tutorial viewed in
a web browser
This tutorial assumes the reader is familiar with MyEclipse web
project development and deployment concepts and tools and the
MyEclipse
Database Explorer features. If during the course of this
tutorial you have questions or would like further information
about the topics presented in this tutorial please consult the
Resources section for additional
resources. To get a better feel for the full scope of MyEclipse,
please check out our product
documentation.
This tutorial was created using MyEclipse 6.0.1 Professional
Edition. If you are using a more recent version of MyEclipse,
most of the images and instructions should be backward
compatible.
MyEclipse Reports requires MyEclipse 6.0.1 or above. It is a
Professional level feature and is only available to MyEclipse Pro
subscribers.
|
|
Our customer listing report will retrieve its data from the local
MyEclipse Derby Server. You can use any database for which you
can configure a JDBC driver in the Database Explorer, e.g.,
Oracle, MS SQL Server, etc. The MyEclipse Derby server is provided
as a training convenience as part of the MyEclipse 6 Server
Sandbox and includes a preconfigured JDBC driver.
-
Launch the MyEclipse Derby server if it is not already running.
In the Servers view, select the MyEclipse Derby Server and
choose Run Server from the context menu or the Run action on the
Servers view toolbar.
Working with the Embedded Derby database is covered in this
tutorial. If you wish to follow along use a different database,
please ensure it is running at this point.
-
Launch the Data Source Wizard. In the Data Explorer view, select
Data Sources > New Data Source from the context
menu. If the Data Explorer view is not visible you can launch it
from the menubar,
Window > Show View > Other > MyEclipse Reports
Design > Data Explorer.
Figure 5-1, New Data Source action
-
Select "MyEclipse JDBC Data Source" from the list of
data source types
-
Enter "Data Source" in the Data Source Name field
-
Click Next>.
Figure 5-2, select the Data Source type
-
Select the preexisting "MyEclipse Derby" driver and
click Finish.
Note: you could also choose actions to create or edit an
MyEclipse JDBC driver from this page.
Figure 5-3, Select the Database Driver
The reportdemo's data source is now configured to fetch its data
using the MyEclipse Derby JDBC driver. For more information about
working with MyEclipse JDBC Data Source see the
Working with MyEclipse
JDBC Data Sources Tutorial.
|
|
With the data source and data set created, the next step is to
add the user interface elements to the report that will display
the data from the Customers data set. We will start by adding a
table element to the report. Then we will bind columns from the
data set elements to the columns in the report table. It is
important to understand the functionality that the table
provides:
-
The table iterates through all the data rows of a data set
-
It enables you to layout data easily in a row and column format
-
Select the Palette view to view the elements that can be added
to a report.
Figure 7-1, Palette View
-
Drag a table element
from the palette and drop it on the report in the Layout Editor.
A new Table dialog will appear and prompt you for the number of
columns and detail rows to create for the new table and the data
set to bind to the table.
-
In the new Table dialog, specify the following values, as shown
in Figure 7-2.
-
Number of columns: 3
-
Number of details: 1
-
Data Set: select Customers from the drop-down list
-
Choose OK
Figure 7-2, Insert Table Dialog properties
A table with three columns and one detail row appears in the
Layout Editor.
Next we will bind data set elements to columns of the table.
-
In the Data Explorer view, expand the Customers data set to view
the columns that we specified in the query.
-
Drag the CUSTOMERNAME column from Data Explorer and drop it in
the first cell of the table's detail row as shown in Figure 7-3.
The table detail row defines the columns of the data set and
their order of display in each data row of the table. In the
finished report, the detail row is repeated for each row of data
in the data set.
Figure 7-3, Dragging a data set column and dropping it
in a table cell
When the CUSTOMERNAME column from the data set data set was
dropped on the detail row, the Layout Editor added the
[CUSTOMERNAME] data binding element. Additionally, in the header
row above the new [CUSTOMERNAME] data element, the Layout Editor
automatically added a column heading label with text,
e.g., CUSTOMERNAME. Figure 7-4 shows the data and label elements.
Figure 7-4, Data and label elements in a table
-
Drag the PHONE column from Customers data set and drop it in the
second cell of the detail row.
-
Drag the CONTACTFIRSTNAME column from the Customers data set and drop
it in the third cell of the detail row.
-
Drag the CONTACTLASTNAME column from the Customers data set and drop
it in the fourth cell of the detail row, below CONTACTFIRSTNAME.
The report layout should appear as shown in Figure 7-5 below.
Figure 7-5, Customer and contact information added to a table
-
To confirm that the report data and table layout are correct
choose the Preview tab at bottom of the Report Designer.
See Figure 7-6 for how the report preview should appear. You can
also preview the report other formats such as PDF by choosing
File->
View Report->
View Report as PDF from the main menubar.
Figure 7-6, Preview of report data
In Figure 7-6 we can see in the report preview that data rows are
displayed in the order that they are returned by the Customers
data set query. The default data row ordering can be influenced
by many factors, such as the order in which data was created in
the database. In most cases, you will want to change the order in
which data appears in the report. This section will introduce how
to sort report data.
-
In the Report Designer choose the Layout tab to return to the
Layout Editor
-
Open the Property Editor View, if necessary. If you use the
default Report Design perspective, the Property Editor appears
just below the Report Designer in the bottom-center section of
the workbench. If the view is not visible, choose
Window >
Show View >
Property Editor.
-
In the Layout Editor, select the table by selecting the Table
tab in the lower left corner. This tab appears when you hover
the mouse pointer over this area. The Property Editor will
display the selected table properties as shown in Figure 7-7.
Figure 7-7, Table Property Editor
-
Choose the Sorting tab
-
Choose Add to specify a sort key. This will open the New Sort
Key dialog. See Figure 7-8.
-
In the New Sort Key dialog, specify the following values:
-
Key: select CUSTOMERNAME
-
Direction: select Ascending
Figure 7-8, New Sort Key dialog
-
Choose OK. The Sort page will add the new CUSTOMERNAME sort key
that you defined for the table
-
Preview the report again. This time the data rows appear in
ascending sort order on the CUSTOMERNAME column data. See Figure
7-9.
Figure 7-9, Preview of data sorted on the CUSTOMERNAME column
Notice that names with uppercase letters appear at the top of
the list. MyEclipse Reports sorts string data by UCS2 code point
values. In ASCII-based character sets, uppercase letters have
lower code point values than lowercase letters. Therefore,
uppercase letters appear before lowercase letters.
Next let's sort the customer names case-insensitively so that
ANG Resellers appears after American Souvenirs Inc., rather than
before it.
-
In the Property Editor select the Sorting tab. Next select the
CUSTOMERNAME sort key as shown in Figure 7-10, followed by the
Edit button. This will open the Sort Key Editor.
Figure 7-10, New key on Sorting page
-
In the Sort Key Editor, change the Sort Key expression to the
following expression and choose OK.
row["CUSTOMERNAME"].toUpperCase()
This expression uses the JavaScript toUpperCase() function to
convert all the customer name values to uppercase before
sorting. JavaScript function names are case-sensitive, so you
must type toUpperCase() exactly as shown. References to column
names are also case-sensitive. In this expression,
row["CUSTOMERNAME"] is the correct name to use. If you
type row["customername"], for example, the Report
Designer displays an error when you run the report. You can
verify the capitalization of a column name by looking at its
spelling in the Data Explorer.
-
Preview the report and confirm that the customer names appear in
case insensitive ascending order.
Now that the report displays the data in the correct order, we can
turn our attention to improving the report's appearance. In this
section we will perform the following tasks:
-
Edit column heading labels
-
Format column headings to differentiate them from the data rows
-
Display the contact first and last names on the same line
-
Increase the space between rows
7.3.1 Edit Column Heading Labels
-
In the Report Designer, choose the Layout tab to return to the
Layout Editor
-
The Layout Editor allows you to edit labels directly. Place the
cursor in the label text insert and delete characters directly.
Hit Enter to save the new label text. Replace the CUSTOMERNAME
column heading with the following text:
Customer
-
Repeat step 2 to change the second and third column
headings to the following text:
Phone Contact
The report design should look like the one shown in Figure 7-14.
Figure 7-11, Revised column headings
7.3.2 Format Column Head Labels
To format a report element, you set its properties. You can
accomplish this task in two ways:
-
Set an element's properties through the Property Editor.
-
Define a style that contains the desired properties and apply
the style to an element. Use this method to define format
properties once and apply them to more than one element.
In this procedure, we will use the first method, Property Editor,
to set the column headings to bold. The second method will be
used add color to the header row.
-
To set the column headings to bold using Property Editor:
-
Select all the column headings. To select multiple elements,
press the Shift key as you click each element. The Property Editor
displays the properties for the selected elements, as shown in
Figure 7-11 above.
-
Choose the 'B' style option to format the selected column
headings as bold text
-
To deselect the column headings, click the whitespace outside
the table.
-
To add a background color to the header row, using a style:
-
From the main menu bar, choose Element->New Style.
New Style appears, as shown in Figure 7-12. The left side
displays the property categories. The right side displays the
properties for the category that you select.
Figure 7-12, New Style Editor
-
Select the Custom Style option and specify the following name for the style:
table_header_row
-
Choose Background from the list of property categories. New
Style displays the background properties that you can set.
-
Specify a color for the Background Color property, using one of
the following methods:
-
Select the button next to the property, then select a color
from the color palette that appears.
-
Select a color from the drop-down list.
Choose OK.
-
In the Layout Editor, select the table by selecting the Table
tab in the lower left corner. This tab appears when you hover
the mouse pointer over the lower left corner of the table.
Clicking the table causes guide cells to appear at the top and
left side of the table, as shown in Figure 7-13.
Figure 7-13, Guide cells at top and left of a table
-
Select the guide cell next to the header row. The Property Editor
will display the properties for the selected row.
-
Choose Properties and then General to display the general
properties for the row.
-
Apply the style that you just created by selecting
table_header_row from the drop-down list next to Style. The
Report Designer applies the style to the header row and it
appears in color.
- Preview the report. The report should look like the one shown
in Figure 7-14.
Figure 7-14, Report preview with improved header row styling
7.3.3 Display First and Last Names on Same Line
When you place multiple elements in a single cell, MyEclipse
Report Designer creates block-level elements. If you are
familiar with HTML, you know that each block element starts on a
new line. To display multiple elements on the same line, you
need to set them as inline elements. Alternatively, you can
concatenate the first and last name values to display in a
single data element, as described in this procedure.
-
In the Report Designer choose Layout to return to the Layout Editor.
-
Delete the data element that displays [CONTACTLASTNAME].
-
Double-click the data element that displays [CONTACTFIRSTNAME].
Edit Data Item Binding, shown in Figure 7-15, provides information
about the data associated with the current data element. In
Expression, dataSetRow["CONTACTFIRSTNAME"] indicates
that the data element displays data from the CONTACTFIRSTNAME
field in the data set.
Figure 7-15, Edit Data Binding
-
Click the Expression Builder button next to
dataSetRow["CONTACTFIRSTNAME"].
The Expression Builder displays the expression in the text area at
the top of the window.
-
To concatenate the first and last names, edit the expression as
follows:
dataSetRow["CONTACTFIRSTNAME"]+" "+ dataSetRow["CONTACTLASTNAME"]
Figure 7-16 depicts this expression in the Expression Builder. The
empty quotation marks (" ") add a space between the
first name and last name. You can type the expression in the
text area, as shown in Figure 7-16 or double-click an item in
the lower right of the window to insert it in the expression.
Figure 7-16 shows a column name that you can double-click to
insert into the expression.
Figure 7-16, Concatenated data in the Expression Builder created by
choosing a data set field
-
Choose OK to close Expression Builder.
The edited expression appears in Edit Data Item Binding. Choose
OK to save the changes to the data element.
-
Preview the report. The report should look like the one shown
in Figure 7-17.
Figure 7-17, Report preview
7.3.4 Increase Space Between Rows
The default layout adds minimum space between table rows.
Typically, you will want to adjust the spacing between rows.
-
Choose Layout to return to the Layout Editor.
-
Select the table's detail row, i.e., the middle row as shown in
Figure 7-18.
Figure 7-18, Selected table row in the Layout Editor
The Property Editor displays the properties for the row. The title
that appears in the Property Editor shows the type of element that
you select, so you should see Property Editor - Row.
-
In the General properties, set Height to 24 points. This will increase the height
of each row increases, as shown in Figure 7-19.
-
Preview the report. The report should look like the one shown
in Figure 7-19. There is more space between the rows of data.
Figure 7-19, Report preview with expanded row spacing
To wrap up our report needs a title. To display a title, you
can use either a label element, a text element, or a data
element:
-
The label element is suitable for short, static text, such as
column headings
-
The data element is suitable for displaying dynamic values from
a data set field or a computed field
-
The text element is suitable for multi-line text that contains
different formatting or dynamic values
In this procedure, you use a text element and HTML tags to
format the text. Note that you are not required to use HTML to
create formatted text. If, however, you are well-versed in HTML
or web design, you might prefer using HTML to create a block of
formatted text.
-
In the Report Designer, choose the Layout tab to access the
Layout Editor
-
From the Palette view drag a text element and drop it above the
table. This will open the Text Item Editor
Figure 7-20, Drag and dropping a Text element to create Report
heading
-
On Edit Text Item, select HTML from the drop-down list that
displays Auto.
Selecting HTML enables you to embed HTML tags or CSS properties
in the text. You can type the tags or you can insert the
commonly used HTML tags that the text editor provides.
-
Enter the following HTML in the text area, shown in Figure
7-21:
<CENTER> <SPAN style="font-size: larger"> <B>Customer List</B> </SPAN> <BR> <FONT size="small">For internal use only</FONT> <BR><BR> Report generated on <VALUE-OF>new Date( )</VALUE-OF> </CENTER> <BR><BR>
Figure 7-21, Text with HTML Tags
-
Choose OK, then preview the report. The report should appear
similar to the report shown in Figure 7-22.
Figure 7-22, Report preview, showing formatted report title
As you can see, using the text element with embedded HTML enables
you to:
-
Use different formatting for each line in a multi-line text
block.
-
Insert dynamic values such as the current date.
Alternatively, you can use:
-
Two label elements to display the first and second lines of
static text
-
A data element to display the third line that contains the
dynamic value
|