Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
506 views
in Technique[技术] by (71.8m points)

Jasper Reports Show "Page X of Y" using a single text field

I would like to create one text field that contains Page X of Y, without splitting it in two parts, as per the common solution. My textfield contains "Page " + $V{currentPage} + " of " + $V{PAGE_NUMBER}" with evaluationTime=auto.

Let's say I have a report with 10 pages. Three are the Title Band, six are Detail Band and one is the Summary Band. My results show "Page 0 of 10" for the Title Bands, correct counts for the Detail Bands, then "Page 0 of 10" for the Summary Bands.

How do you ensure the variable is calculated everywhere, not only on Detail Band?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Jaspersoft Studio, 6+

For Jaspersoft Studio v6, or if the first page number is duplicated, try this solution, which uses $V{MASTER_CURRENT_PAGE} and $V{MASTER_TOTAL_PAGE} with an evaluation time of Master.

Jaspersoft Studio

For other versions of Jaspersoft Studio, try the steps outlined in the subsequent subsections.

Create Variable

Create a variable as follows:

  1. Create a variable called V_CURRENT_PAGE_NUMBER
  2. Select the variable to open its properties (illustrated below)
  3. Set Expression to: 1
  4. Set Initial Value Expression to: $V{PAGE_NUMBER}
  • If the page number shows 0, use $V{PAGE_NUMBER} + 1.
  • If the page number always shows 1 of Y, set Expression to $V{PAGE_NUMBER} instead of the initial value expression, and leave the initial value expression empty.
  1. Set Reset type to: Page

These settings are illustrated in the following figure:

Current Page Number Variable

Setting the Expression to 1 prevents its value from being null. That is, if the footer shows Page null of 4 it probably means that the Expression hasn't been set.

The variable is created.

Add Page Footer

Add a Page Footer band as follows:

  1. Select the report in the outline panel
  2. Check Summary With Page Header And Footer to ensure the page footer appears on the summary page.
  3. Add a Page Footer band.

The footer is added.

Create Text Field

Create a text field as follows:

  1. Drag and drop a single text field onto the Page Footer band.
  2. Select the text field.
  3. Set Expression to: msg("Page {0} of {1}", $V{V_CURRENT_PAGE_NUMBER}, $V{PAGE_NUMBER})
  4. Set Evalutation Time to: Auto

These settings are illustrated in the following figure:

Single Text Field

The single text field is created.

Preview Report

For a report with three pages plus a summary page, previewing the report shows:

Page 1

The summary page shows:

Page 4


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...