JasperReports allows you to filter records during report processing and show only those of interest in a particular report. This recipe teaches you how to use this feature of filtering of records during report processing.
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 create a database named jasperdb2
and copy sample data for this recipe into the database.
Following simple steps demonstrate how you can filter records to be shown in a report:
FilteringReportRecords.jrxml
file from the Task4
folder of the source code for this chapter. The Designer tab of iReport shows a report with a simple table in its body, as shown in the following screenshot: Packt Publishing
and Mar09
as the value for the customer name and invoice month parameters, respectively. You will see a report of invoices for the particular customer for a specific invoicing month, as follows: parameter1
at the end of the parameters list. Select parameter1
from the list; its properties will appear in the Properties window below the palette of components on the right of your iReport main window. MinInvoiceValue
as its value. Now click the Parameter Class property and change its value to java.lang.Integer
. Leave the rest of the parameter properties at their default values. $F{InvoiceValue}.intValue() >= $P{MinInvoiceValue}
in the editor window and click the OK button, as shown in the following screenshot: Packt Publishing, Mar09
, and 5000
as values for the customer name, invoicing month, and min invoice value parameters, respectively and click OK. You will see a report of invoices whose values are greater than 5000
for the particular customer for the specific invoicing month. Note that this report is a subset of the report shown in the preview of step 3.You have used a combination of parameters and Print When expression features of JasperReports in this recipe. You use parameters to allow users of your report to enter data just before report processing. For example, you included a parameter named MinInvoiceValue in step 6 of the recipe.
Then you used the MinInvoiceValue parameter in the $F{InvoiceValue}.intValue() >= $P{MinInvoiceValue}
expression in step 8. This expression prints a record only when the InvoiceValue field in a record is greater than or equal to the value that a user enters as the MinInvoiceValue parameter. You can see this by comparing the previews of steps 3 and 10.
3.21.106.7