TIBCOSoftware / jasperreports

JasperReports® - Free Java Reporting Library
https://community.jaspersoft.com/downloads/community-edition/
GNU Lesser General Public License v3.0
1.06k stars 403 forks source link

Evaluation time "auto" does not always work correctly with variables and their reset types "page" / "group" #196

Open jnehlmeier opened 3 years ago

jnehlmeier commented 3 years ago

Hi,

we have reports with a page footer containing the usual "page x of y" text which has traditionally been implemented using two textfields. Each of them contains $V{PAGE_NUMBER} with one textfield having evaluation time now and the other has evaluation time report or group (depending on the report).

Now we upgraded to Jasperreports 6.17.0 and thought that always managing two textfields is annoying since you can not nicely align them to the right (since you don't know the total number of pages and you have to reserve some unknown space to the right). So we used a different approach with a single textfield and evaluation time auto. I think this is the recommend way these days.

So we created two variables CURRENT_PAGE_NUMBER (reset type page) and TOTAL_PAGE_NUMBER (reset type report or group depending on report) and put them into a single textfield with evaluation time auto. Both variables have expression $V{PAGE_NUMBER}, no calculation function and no initial value.

This mostly works but some of our reports produced wrong page numbers. Basically for a given group the amount of total pages was missing one page and on that last page of the group the current page number is null.

Reproduction example

evaluation-time-auto-bug.zip

I have attached an example jrxml + csv data file that reproduces the issue. The example contains both approaches described above so you can see the difference between both.

  1. Extract attached zip file
  2. Open file evaluation-time-auto-bug.jrxml in jasper studio
  3. Create a CSV data adapter and use the file jasperreports_testdata.csv. Hit the button Get column names from the first row of the file and make sure to check skip the first line below in the other section. The wizard should detect 5 column names (two groups with id + data columns and a detail_data column)
  4. Now open the preview of the report and choose the created CSV data adapter to populate the preview.

You should now see 6 pages and the page numbers of the last two pages shown in the evaluation time auto textfield are wrong. The page numbers basically miss the last page:

In our real reports this issue does not only happen on the very last pages of the last group of the report but can happen on any group within the report. Basically whenever detail bands of the last page within a group have to be moved to a new page.

teodord commented 3 years ago

I can explain why it works this way, but it would probably not help you.

i don't see any workaround yet.

DougAtCordiance commented 1 year ago

The recommended approach to "Page X of Y" is to use $V{MASTER_CURRENT_PAGE} for X with evaluationTime set to "Master" and ${MASTER_TOTAL_PAGES} for Y also with evaluation time set to 'Master'.