Skip to main content

Post 14: iReport:Using parameters to filter records during report processing

Using parameters to filter records during report processing:
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.

Getting ready 
Refer to the Post6:  iReport: Installation of PostgreSQL, which shows how you can install and run PostgreSQL. Note that your installation of PostgreSQL should be up and running before you proceed.

Refer to the post named Copy Sample Data Into Postgres  which helps you to create a database named jasperdb2 and copy sample data for this post into the database. 

How to do it...
Following simple steps demonstrate how you can filter records to be shown in a report:
1.  Create the FilteringReportRecords.jrxml file as the Designer tab of iReport shows a report with a simple table in its body, as shown in the following screenshot:


2.  Switch to the Preview tab, and Parameter prompt dialogs will appear, which will ask you for a CustomerName and InvoicePeriod parameters, as shown in the following screenshot:
 

3.  Type Packt Publishingand 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:





4.  Switch back to the Designer tab. Right-click on the Parameters node in the Report Inspector window on the left of the Designer tab, as shown next. A pop-up menu will appear. Choose the Add Parameter option from the pop-up menu.



5.  The Parameters node will expand to show the newly added parameter named parameter1at the end of the parameters list. Select parameter1from the list; its properties will appear in the Propertieswindow below the palette of components on the right of your iReport main window.

6.  Click on the Name property of the parameter and type 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.


7.  Click inside the Detail 1 section; its properties will appear below the palette of  components. Click the button beside the Print When Expressionproperty

A Print When Expression window will open, as shown in the following screenshot:
 

8.  Add the expression text $F{InvoiceValue}.intValue() >=
$P{MinInvoiceValue}in the editor window and click the OK button, as shown in the following screenshot:




9.  Switch to the Preview tab; Parameter prompt dialogs will appear, which will ask you for a customer name, invoicing month, and minInvoice value parameters, as shown in the following screenshot:



10. Type Packt Publishing, Mar09, and 5000as 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 5000for 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.



How it works...
You have used a combination of parameters and Print When expression features of  JasperReports in this post. 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 post.


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 InvoiceValuefield in a record is greater than or equal to the value that a user enters as the MinInvoiceValueparameter. You can see this by comparing the previews of steps 3 and 10.


Comments

Popular posts from this blog

TIME TABLE: VTU BE/B.Tech June/July 2016 Exam Time table Draft Layout

Semester-wise June-July 2016 Exam time table (Draft Layout) Are You Using updated Kwikstudy App?

Walkins Bangalore: 01st-Oct-2016

1. UTC Aerospace : GET – S&IS-Software Team hiring Electronics & CSE / IT Freshers ! Walkin on 1st OCT | BE/BTECH - 2015 & 2016 both batch can try Selection Process : Written Test Group Discussion Technical & HR Interviews How To Apply : It is a walk-in drive for 2016 batch eligible freshers on 1 Oct 2016 at Bangalore location. Interested and eligible candidates can walk-in to the following venue on 1 Oct 2016 Date of Drive : 01 Oct 2016 Reporting Time : 8:00 AM to 11:30 AM Venue : UTC Aerospace Systems – Site 1, Sy. Nos. 14/1 & 15/1, Maruthi Industrial State, Phase 2, Hoody Village, Whitefield Road, K R Puram Hobli, Bangalore – 560048 ______________________________________ 2. HP : Software Eng/ Software Tester (Call based ,less chance of getting entry , try at your own risk) Event Date : 1-October-2016 Event Time : 8 : 00 am Job Location : Bangalore / Chennai Job Description: Software Engineer /

How to get VTU Provisional Degree Certificate (PDC) ?

Here is the procedure to get the Provisional Degree Certificate from the VTU by passed out candidates. You can get the certificate through post by sending the required documents to VTU. Documents and things required: 1. Provisional Degree Certificate (PDC) application form 2. DD of specified fees amount or print copy of receipt if you paid the fees online 3. A letter to the VTU registrar 4. A4 size envelope Step 1: Fill the PDC application You can download the PDC application form from the VTU website. Click below link for application download. PDC application form download     After downloading the application take a print of it and properly fill the form. Step 2: Make a DD of specified amount as the fees of PDC: Go to the bank and make the DD of prescribed fee amount for the PDC. The fee amount is specified in the above link from where you downloaded the application. Make the DD in favor of " Finance Officer, VTU Belgaum ".   Wr