JasperProcess Mini Tutorial

Top  Previous 

In this mini tutorial it is explained how to generate a simple report with JasperProcess step by step.

The Objective:

Generating a report that lists the product categories stored in the product_categories table of the SuperStore sample database.

Like other process elements, the JasperProcess element can also be used by placing it into a ProcessForm or a ProcessBlock element. Before configuring a JasperProcess element there has to be a report template that can be prepared with JasperReports iReport Tool.

The report files prepared with iReport are either in jrxml (XML text) or in jasper (compiled) format. If you're familiar with the jrxml file structure you can also prepare it even with notepad.

Steps:

1.Copy the XML provided below into a text editor. e.g. Notepad.

<?xml version="1.0"?>

<!DOCTYPE jasperReport PUBLIC "-//JasperReports//DTD Report Design//EN" "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">

<jasperReport name="categories">

<parameter name="TITLE" class="java.lang.String"/>

<field name="NAME" class="java.lang.String"/>

<title>

   <band height="90">

     <textField>

       <reportElement x="0" y="10" width="535" height="80" forecolor="#FF0033"/>

       <textElement textAlignment="Center">

         <font size="32"/>

       </textElement>

       <textFieldExpression class="java.lang.String">

        <![CDATA[$P{TITLE}]]>

       </textFieldExpression>

     </textField>

   </band>

</title>

<detail>

   <band height="40">

     <textField>

       <reportElement x="0" y="0" width="535" height="40"/>

       <textElement textAlignment="Left">

         <font size="24"/>

       </textElement>

       <textFieldExpression class="java.lang.String">

        <![CDATA[$F{NAME}]]>

       </textFieldExpression>

     </textField>

   </band>

</detail>

</jasperReport>

 

TITLE : The title of the report which is defined as a parameter. [parameters] $P{TITLE}

NAME   : The column name existing in the result set that returns from the SQL query which is defined as Field. [field] $F{NAME}

 

The XML content above is the report template and it contains one parameter called TITLE and one field in the repeating band called NAME. The NAME field in the band will resolve to the name of the product categories returned from the query.

 

2.Save the pasted content as Categories.jrxml somewhere on the disk.

 

3.Right click on the Site1 icon on the project explorer and choose "New Folder" on the context menu. Check the "Server item types" checkbox on the dialog and choose "JasperReports Files" from the list.
 

AddFolder

The folder "JasperReports Files" will be created on the project explorer.

 

4.Right click on this new folder and choose "Insert File" option on the context menu. Click on the [Bring file...] button on th dialog and locate the Categories.jrxml file the you prepared on the disk and bring to the focused project folder. It will appear on the Insert file(s) dialog. Check the file and click on the [OK] button.

InsertReport

 

5.Open a new page and place "zpro > ProcessForm" library element into it.
6.Place an editbox element in the form and name it as "REPORT_TITLE"
7.If no JDBC connection is defined in the project yet, define it with "mor > RelDB > RelDBConnection" library element in the Common Definitions page. It is assumed that the name of the element and the connection is "SS".
8.Now, place a "mor > Reporter > JasperProcess" element into the process form and set its properties as follows:

Tutor_JasperProcess
 
The definition of the properties say that the Jasper Report template Categories.jrxml will be filled with the data obtained with the
"SELECT * FROM product_categories" query using the "SS" connection and a temporary PDF file will be created and the name of the temporary file will be stored in v:categoryPDF symbol.
 

9.Place "mor > Reporter > FileToBrowserProcess" element into the process form and configure it as follows to send the generated temporary PDF file to the browser.
 
Tutor_FileToBrowserProcess
 
10. Place "zpro > ProcessForm > ExcecuteCommand" element into the process form and configure it as follows to trigger the execution of the configured process elements.

Name

GenerateReport

Process List

<callProcess name="GenerateReport" if="_maxlcc = 0"/>
<callProcess name="SendToBrowser" if="_maxlcc = 0"/>

Next Page

%vof(PAGE_NAME)

 

After completing this step the view on the page design area should be similar to the following.

Tutor_DesignArea

 

10.Now we can build the project and test the page.

 
The report will be generated and sent to the browser. The PDF should be visible in the browser area as follows.
 

BrowserView