13.07.2015 Views

iReport Ultimate Guide - Nimsoft Library

iReport Ultimate Guide - Nimsoft Library

iReport Ultimate Guide - Nimsoft Library

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>iReport</strong> <strong>Ultimate</strong> <strong>Guide</strong>With 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

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!