iReport Ultimate Guide - Nimsoft Library
iReport Ultimate Guide - Nimsoft Library iReport Ultimate Guide - Nimsoft Library
iReport Ultimate GuideWith some effort it is possible to produce the same text using in a single textfield. The advantage of using a single textfield isthat it gives you better control over the formatting of the text; in some languages and locales, the text of the fields containingthe current and the total number of pages can vary. With a single textfield, the text does not have to be split into two portionswith separate formatting.This result can be achieved by using the evaluation time Auto for the textfield elements. This evaluation time considers all thevariables involved in the textfield expression at the time specified by their reset type (reset type is a property of eachvariable; it specifies when the variable must be reset). For instance, the reset type of the PAGE_NUMBER built-in variable isReport, so when PAGE_NUMBER variable is printed in a textfield having evaluation time Auto, what is printed is the totalnumber of pages (the value of the variable PAGE_NUMBER at the time of its next reset, which in this case is the end of thereport).The trick to evaluating PAGE_NUMBER at two different evaluation times in the same expression is creating a new variablewhich holds the current page number and has reset type Page. To create such of variable is pretty straightforward, just add anew variable and set the following properties:PropertyVariable nameVariable classCalculationReset typeVariable ExpressionAll other propertiesValuecurrentPagejava.lang.IntegerNothingPage$V{PAGE_NUMBER}DefaultsEvery time a new page is created, this new variable assumes the value of the variable PAGE_NUMBER (which holds the currentpage number). Until the next page is reached, this variable will still have the value of the current page. Since the reset type ofthis variable is Page, when used in a textfield with evaluation time Auto the variable’s value will be the current page number.Let’s put everything together:1. We need a textfield with evaluation time Auto and class java.lang.String having the following text expression:"Page "+$V{currentPage}+" of " + $V{PAGE_NUMBER}2. As expected, the result of this expression will be something like:Page 4 of 30 (where 4 is the current page and 30 the total number of pages in the report).This expression can be totally changed but the value represented by $V{currentPage} will remain the current page, whilethe value $V{PAGE_NUMBER} will be the total number of pages. This allows using expressions like:MyUtils.formatPageXofY($V{currentPage}, $V{PAGE_NUMBER})where MyUtils.formatPageXofY can be a user-defined method to generate the Page X of Y label from the value of thecurrent page and the total number of pages.For more information on creating variables, PAGE_NUMBER, and evaluation times, see Chapter 6, “Fields, Parameters, andVariables,” on page 95.19.3 Percentage ToolThe Percentage tool helps the user create a text field containing a percentage. When you drag-and-drop the Percentage toolinto a report band, the dialog box shown in Figure 19-4 appears. Here you specify the field whose percentage you want tocalculate and the aggregation level on which to perform the calculation.348
Additional ToolsFigure 19-4Percentage tooliReport creates a new variable to store the sum of the selected field. The reset type of this variable is set to the selectedaggregation level (such as report, page, or a particular group). The text field expression generated is something like this:new Double( $F{FREIGHT}.doubleValue() / $V{FREIGHT_SUM}.doubleValue() )and the evaluation time is set to Auto to allow the evaluation of $F{FREIGHT} and $V{FREIGHT_SUM} at differentaggregation times.Finally, the pattern of the text field is set to #,##0.00%.19.4 Using a Background Image as ReferenceWhen a report is designed for a pre-printed page or when it must recreate an existing document exactly, it is convenient todisplay a reference image of the pre-printed page or existing document in the designer (Figure 19-5). This can beimplemented by selecting the menu item View > Report Designer > Import Background Image. The image path andproperties are stored in the JRXML so that, when the document is closed and reopened, you don’t have to set the imageproperties again.349
- Page 297 and 298: Lists, Tables, and BarcodesWhen usi
- Page 299 and 300: SubdatasetsCHAPTER 15 SUBDATASETSRe
- Page 301 and 302: SubdatasetsUR permits you to use a
- Page 303 and 304: SubdatasetsFigure 15-7Initial layou
- Page 305 and 306: SubdatasetsFigure 15-11 Pie dataset
- Page 307 and 308: CrosstabsCHAPTER 16 CROSSTABSA cros
- Page 309 and 310: CrosstabsUsing the Crosstab Wizard,
- Page 311 and 312: CrosstabsFigure 16-6Outline tree vi
- Page 313 and 314: CrosstabsFigure 16-8Adding a Row Gr
- Page 315 and 316: CrosstabsFigure 16-11 Empty row tot
- Page 317 and 318: CrosstabsFigure 16-16 Crosstab Prop
- Page 319 and 320: CrosstabsFigure 16-19 Crosstab Data
- Page 321 and 322: CrosstabsFigure 16-22 The result of
- Page 323 and 324: InternationalizationCHAPTER 17 INTE
- Page 325 and 326: InternationalizationFigure 17-2Crea
- Page 327 and 328: InternationalizationFigure 17-6New
- Page 329 and 330: InternationalizationFigure 17-7Loca
- Page 331 and 332: ScriptletsCHAPTER 18 SCRIPTLETSA sc
- Page 333 and 334: ScriptletsTable 18-1Report eventsEv
- Page 335 and 336: ScriptletsFigure 18-3Adding a Jar t
- Page 337 and 338: ScriptletsFigure 18-5Build output18
- Page 339 and 340: ScriptletsIf you want to add more s
- Page 341 and 342: ScriptletsThis is what you get in t
- Page 343 and 344: Scriptletsterminates the report exe
- Page 345 and 346: Additional ToolsCHAPTER 19 ADDITION
- Page 347: Additional ToolsFigure 19-3Date and
- Page 351 and 352: 19.5 How to Run the SamplesAddition
- Page 353 and 354: Chart Theme ExampleAPPENDIX ACHART
- Page 355 and 356: Chart Theme ExampleCode Example A-1
- Page 357 and 358: IndexINDEXAAdd selected field(s) 20
- Page 359 and 360: Indexcomponents 241embedded in Java
- Page 361 and 362: Indexscriptlets 53sheets. See prope
Additional ToolsFigure 19-4Percentage tool<strong>iReport</strong> creates a new variable to store the sum of the selected field. The reset type of this variable is set to the selectedaggregation level (such as report, page, or a particular group). The text field expression generated is something like this:new Double( $F{FREIGHT}.doubleValue() / $V{FREIGHT_SUM}.doubleValue() )and the evaluation time is set to Auto to allow the evaluation of $F{FREIGHT} and $V{FREIGHT_SUM} at differentaggregation times.Finally, the pattern of the text field is set to #,##0.00%.19.4 Using a Background Image as ReferenceWhen a report is designed for a pre-printed page or when it must recreate an existing document exactly, it is convenient todisplay a reference image of the pre-printed page or existing document in the designer (Figure 19-5). This can beimplemented by selecting the menu item View > Report Designer > Import Background Image. The image path andproperties are stored in the JRXML so that, when the document is closed and reopened, you don’t have to set the imageproperties again.349