This recipe teaches you how to play with variables to give a stylish and professional look to the simple Table of contents (TOC) you designed in the Creating a simple one-page TOC for your report recipe. For this purpose, you will use four pairs of variables and text fields to design a stylish TOC. You will configure each pair individually.
Refer to the installPostgreSQL.txt
file included in the source code download of this chapter to install and run PostgreSQL, which should be up and running before you proceed. The source code of this chapter 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.
StylishTOCReport.jrxml
file from the Task3
folder of the source code of this chapter. 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: ($V{FirstRecordOfANewGroup}==0) ? $V{TOC} + ($F{CustomerName} +"<br/>") :$V{TOC}
as the expression in the Variable Expression window. TOC_PageIndex
. Now the name of the variable1 variable will change to TOC_PageIndex. java.lang.String
. Report
. ($V{FirstRecordOfANewGroup}==0) ? ($V{TOC_PageIndex}+$V{PAGE_NUMBER} + "<br/>") :$V{TOC_PageIndex}
as the expression in the Variable Expression window, as shown below. Press the OK button. new java.lang.String()
as its value. StylishTOCReport.jrxml
file. You have to close and re-open your .jrxml
file every time you play with the Initial Value Expression property of a variable. This is due to a bug in iReport version 3.6.0. $V{TOC}
text field of your report, as shown in the next screenshot: $V{TOC_PageIndex}
text field in the Title section. Its properties will appear in the Properties window below the Palette. Find the Height property and set its value as 100
. $V{TOC_PageIndex}
text field and select Report
as its value from the drop-down list beside it. Similarly, look for the Markup property and select html
as its value from the drop-down list beside it. TOC_Line
. Now the name of the variable1 variable will change to TOC_Line. new java.lang.String()
as its value. ($V{FirstRecordOfANewGroup} == 0) ? ($V{TOC_Index} + $V{Group_Count}+".<br/>") :$V{TOC_Index}
as the Variable Expression value in the expression editor window. StylishTOCReport.jrxml
file. $V{TOC_Index}
text field, as the shown in the next screenshot: $V{TOC_Index}
text field is selected, find the Width property and set its value as 30
. Similarly, set 100
as the value of the Height property. Report
as its value from the drop-down list beside it. html
as its value from the drop-down list beside it. 12
as the value of the Size property in the Properties window.In this recipe you learned a trick of using pairs of variables and text fields to produce a stylish TOC. The recipe uses four pairs:
TOC
and its corresponding $V{TOC}
text field form the first pair, which was already present in the StylishTOCReport.jrxml
file when you opened it in step 1. This pair displays the customer names. Refer to the earlier recipe Creating a simple one-page TOC for your report of this chapter to learn how this pair works. TOC_PageIndex
and its corresponding $V{TOC_PageIndex}
text field form the second pair, which you configured in steps 7 to 18. This pair displays all the page numbers. TOC_Line
and its corresponding $V{TOC_Line}
text field form the third pair, which you configured in steps 21 to 32. This pair displays the dotted line between customer names and page numbers. TOC_Index
and its corresponding $V{TOC_Index}
text field form the fourth pair, which you configured in steps 34 to 51. This pair uses a supporting variable named Group_Count
, which holds the count for the customer names, to display incremental index numbers for the TOC.The common theme between all the pairs of variables and text fields is the use of string concatenation. The variable of each pair keeps on building its content or value for each customer. At the end of report processing, the variable simply copies its value into its corresponding text field. As you want the variable to copy its value into the field only at the end of report processing, you set Report
as the value of the Evaluation Time property for all text fields. Similarly, because each variable uses a<br/>
HTML tag in its expression, you have to set html
as the value of its Markup property.
3.16.79.65