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

by Bilal Siddiqui | June 2010 | Cookbooks Java Open Source

This article by Bilal Siddiqui, author of JasperReports 3.6 Development Cookbook, teaches you to build a simple one-page table of contents(TOC) for your multi-page reports.

(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 3.6

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

    JasperReports 3.6

  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 3.6

  4. A new variable named variable1 will be added at the end of the variables list.

    JasperReports 3.6

  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 3.6

  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 3.6
  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 3.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.

Sign up for a Packt account to see the rest of this article

Now that you've read a few articles, you might want to consider signing up for a Packt account. It takes a matter of seconds, will give you access to all the articles on PacktPub.com, and once you've signed up you'll be returned here to carry on reading your article.

Furthermore, you'll gain access to nine free ebooks, and be offered a free trial of PacktLib, Packt's online library. Simply enter your details here, or log in to your existing account.

Log in

...or register

Post new comment

Awards Voting Nominations Previous Winners
Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
Resources
Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
Sort A-Z