In this recipe you will learn how to design and display a table formulation in the main body of your report. Table formulation includes the following steps:
Refer to the installPostgreSQL.txt
file included in the source code download for this chapter to install and run PostgreSQL, which should be up and running before you proceed. The source code for this chapter also includes a file named copySampleDataIntoPGS.txt
, which helps you to create a database named jasperdb2
and copy sample data for this recipe into the database.
The following steps take you through creating a table:
SimpleTable.jrxml
file from the Task2
folder in the source code for this chapter. The Designer tab of iReport shows an empty report with a title (Monthly Customer Invoices) as shown in the following screenshot: Invoice Number
and press Enter. 0
, as shown in the following screenshot: 0
. The static text component will be positioned to the top-left area in the Column Header section of your report, as shown in the following screenshot: SELECT * FROM "public"."CustomerInvoices"
. Five field names of the CustomerInvoices
table (InvoiceID, CustomerName, ProductName, InvoicePeriod, and InvoiceValue) will appear in the bottom section, as shown in the following screenshot: $F{InvoiceID}
will appear in the Detail 1 section of your report, as shown in the following screenshot: InvoiceID
Field), as shown in the following screenshot: CustomerName, ProductName, InvoicePeriod
, and InvoiceValue
table fields along with their corresponding static text labels into your report. After adding these components your report will look similar to the one in the following screenshot:Switch to the XML tab to see the following JRXML code:
<?xml version="1.0" encoding="UTF-8"?> <jasperReport> <!-- other JasperReports XML tags --> <columnHeader> <band height="20" splitType="Stretch"> <staticText> <reportElement x="0" y="0" width="77" height="16"/> <textElement/> <text><![CDATA[Invoice Number]]></text> </staticText> <!-- other static text tags --> </band> </columnHeader> <detail> <band height="20" splitType="Stretch"> <textField> <reportElement x="0" y="0" width="100" height="20"/> <textElement/> <textFieldExpression class="java.lang.Integer"> <![CDATA[$F{InvoiceID}]]> </textFieldExpression> </textField> <!-- other text field tags --> </band> </detail> <columnFooter> <band height="45" splitType="Stretch"/> </columnFooter> <!-- other JasperReports XML tags --> </jasperReport>
You can see the<columnHeader>, <detail>
, and<columnFooter>
tags in this code. These three tags form the report body (the table) that you designed in this recipe. I have omitted other tags for clarity.
Note that when you executed steps 2 to 5 of the recipe, iReport authored the<columnHeader>
tag. Similarly, when you executed steps 10 to 12, iReport authored the<detail>
tag.
As the recipe did not do anything with the column footer, the<columnFooter>
tag is empty.
52.15.214.27