Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds

JasperReports 3.6: Creating a Simple, One-page TOC for Your Report

Save for later
  • 180 min read
  • 2010-06-30 00:00:00

article-image

(For more resources on JasperReports, see here.)

Getting ready

Refer to the installPostgreSQL.txt file included in the source code download (chap5) to install and run PostgreSQL, which should be up and running before you proceed. The source code also includes a file named copySampleDataIntoPGS.txt, which helps you create a database named jasperdb6 and copy sample data for this recipe into the database.

How to do it...

  1. Open the SimpleTOCReport.jrxml file from the Task2 folder of the source code. The Designer tab of iReport shows a report containing data in Title, Column Header, Customer Group Header 1, Product Group Header 1, Detail 1, and Product Group Footer 1 sections, as shown in the following screenshot:

    jasperreports-36-creating-simple-one-page-toc-your-report-img-0

  2. Switch to the Preview tab and you will see invoices for each customer grouped by product names.

    jasperreports-36-creating-simple-one-page-toc-your-report-img-1

  3. Switch back to the Designer tab. Right-click on the Variables node in the Report Inspector window on the left side of your report. From the pop-up menu that appears, select the Add Variable option.

    jasperreports-36-creating-simple-one-page-toc-your-report-img-2

    Unlock access to the largest independent learning library in Tech for FREE!
    Get unlimited access to 7500+ expert-authored eBooks and video courses covering every tech area you can think of.
    Renews at $15.99/month. Cancel anytime
  4. A new variable named variable1 will be added at the end of the variables list.

    jasperreports-36-creating-simple-one-page-toc-your-report-img-3

  5. While variable1 is selected, find the Name property in the Properties window below the Palette of components and change its value to FirstRecordOfANewGroup. Now the name of the variable1 variable will change to FirstRecordOfANewGroup.
  6. Select the Variable Class property and change its value to java.lang.Integer.
  7. Select the Calculation property and change its value to Count.
  8. Select the Reset type property and change its value to Group.
  9. Select the Reset group property and change its value to Customer.

    jasperreports-36-creating-simple-one-page-toc-your-report-img-4

  10. Select the Variable Expression property and click the button beside it. A Variable Expression window with no default expression will open, as shown in the next screenshot:
    jasperreports-36-creating-simple-one-page-toc-your-report-img-5
  11. Select Variables in the first column of the lower-half of the Variable Expression window. Then double-click the FirstRecordOfANewGroup variable in the second column. A new expression $V{FirstRecordOfANewGroup} will appear in the Variable Expression window, as shown in the next screenshot. Press the OK button.

    jasperreports-36-creating-simple-one-page-toc-your-report-img-6

  12. Right-click on the Variables node in the Report Inspector window. A pop-up menu will appear. Select the Add Variable option.
  13. A new variable named variable1 will be added at the end of the variables list.
  14. While variable1 is selected, find the Name property in the Properties window below the Palette of components and change its value to TOC. Now the name of the variable1 variable will change to TOC.
  15. Select the Variable Class property and change its value to java.lang.String.