You will often need to provide a brief summary or general information about your report on the last page. JasperReports provides you with a section named Summary
, which is displayed before the footer on the last page of your report. For example, if you have a large report of customer invoices, you may display a product-wise summary of invoice totals in the Summary section.
This recipe shows how to display some general information such as the date and time of your report generation as well as the total value of all invoices at the end of your report.
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.
These steps show how to include a summary at the end of your report:
General_Summary.jrxml
file from the Task7
folder in the source code for this chapter. The Designer tab of iReport shows a simple report, as shown in the following screenshot: Date
and Time. Date
is selected by default. You can see different patterns for date in the Type
section. Select a pattern for the date and press Apply button. This will insert a text field component with an expression new java.util.Date()
into the Summary section of your report, as shown in the following screenshot: new java.util.Date()
expression. This report was generated on at
as its value. The text will disappear from the view area, as it is longer than the length of the static text component. Enlarge the rectangular boundary of the static text component by dragging one of its corners, as shown in the following screenshot: on
and at
of the static text component by pressing the space bar 35 times, as shown in the following screenshot: on
and at
, as shown in the following screenshot: $F{ProductName}
will appear in the Summary section of your report, as shown in the following screenshot: Total for all invoices for is
as the summary text in the Summary section of your report. Part of the summary text will disappear from view in the static text component. So, enlarge the rectangular boundary of the static text component by dragging one of its corners, just like in step 6 of this recipe. Invoices for
and is
of the static text by pressing the spacebar 30 times, as shown in the following screenshot: CustomerName
text field component until it sits adjacent to the word Invoices for
of the summary text, as shown in the following screenshot: InvoiceValue
text field component until it touches the boundary of the static text component containing the summary text, as shown in the following screenshot:You dragged-and-dropped a Current date component into the Summary section and configured it to display the date in the required format in steps 2 and 3 of the recipe. Similarly, you dragged-and-dropped the same Current date component into the Summary section and configured it to display the time in step 4 of the recipe.
Then, in steps 5 to 10, you transformed this information into a presentable style. In step 14 of the recipe you dragged-and-dropped the CustomerName field element into the Summary section of your report. iReport intelligently identified that there are a number of records which cannot be displayed in a single text field and therefore presented a dialog window asking your permission for the aggregation function. In step 15, you kept the default selection which was The field value
. This option tells JasperReports to use the first occurring value of the CustomerName field.
Similarly, in step 16, you dragged-and-dropped an InvoiceValue field element into the Summary section. iReport identified that there is more than one entry beside it. Therefore, iReport asked your permission for the aggregation function and you told iReport to perform a sum operation on the values by selecting The result of an aggregation function from the Combo box option.
3.145.107.100