Printing Page X of Y in a Single Textfield logic is breaking when a new page printed with only group footer details.
using Jaspersoft iReport Designer 5.1.0 version
Created variable as below :
<variable name="currentPageNumber" class="java.lang.Integer" resetType="Page" incrementType="Page">
<variableExpression><![CDATA[$V{PAGE_NUMBER}]]></variableExpression>
</variable>
Page number Field :
<textField evaluationTime="Auto">
<reportElement uuid="847e339f-a1a6-492d-868b-b233f71785b4" x="166" y="22" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$V{currentPageNumber} + " of " + $V{PAGE_NUMBER}]]></textFieldExpression>
</textField>
Created a New group Account with print on new page as true, when the new page has only footer part then the page number is showing the page number of previous page.
Please help..........
Please find below comment for the sample jrxml to reproduce this issue.
4 Answers:
Posted on July 8, 2015 at 5:42pm
Are you sure you used evaluation time Auto to display "Page X of Y" in a Single Text field in your repiort design?
Please review the following sample mock up reoport and test it in iReport 5.1 using any PostgreSQL data source to see how it works.
<?xml version="1.0" encoding="UTF-8"?> <jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="-Printing Page X of Y" pageWidth="612" pageHeight="792" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="808f470e-8195-48b4-95af-6b7b557b5900"> <property name="ireport.zoom" value="1.0"/> <property name="ireport.x" value="0"/> <property name="ireport.y" value="0"/> <queryString> <![CDATA[select 1 as n, 'This page has' as t union all select 2 as n, 'two records.' as t union all select 11 as n, 'This page has' as t union all select 12 as n, 'three records.' as t union all select 13 as n, '******' as t union all select 21 as n, 'This page has one record' as t]]> </queryString> <field name="n" class="java.lang.Integer"/> <field name="t" class="java.lang.String"/> <variable name="currentPage" class="java.lang.Integer" resetType="Page"> <variableExpression><![CDATA[$V{PAGE_NUMBER}]]></variableExpression> </variable> <variable name="groupA" class="java.lang.Integer"> <variableExpression><![CDATA[new Integer($F{n}.intValue()/10)]]></variableExpression> </variable> <group name="groupA" isStartNewPage="true"> <groupExpression><![CDATA[$V{groupA}]]></groupExpression> </group> <background> <band splitType="Stretch"/> </background> <title> <band splitType="Stretch"/> </title> <pageHeader> <band splitType="Stretch"/> </pageHeader> <columnHeader> <band height="30" splitType="Stretch"> <staticText> <reportElement uuid="e9eba606-0d40-4bcc-91d4-e22840dc8bf0" x="0" y="0" width="100" height="20"/> <textElement/> <text><![CDATA[Record ID]]></text> </staticText> <staticText> <reportElement uuid="7b977850-d1f4-45bd-9bf4-fc02d20d133e" x="100" y="0" width="300" height="20"/> <textElement/> <text><![CDATA[Text]]></text> </staticText> </band> </columnHeader> <detail> <band height="30" splitType="Stretch"> <textField> <reportElement uuid="b897c39c-5173-4d46-a209-d160dcbd1470" x="0" y="0" width="100" height="20"/> <textElement/> <textFieldExpression><![CDATA[$F{n}]]></textFieldExpression> </textField> <textField> <reportElement uuid="3709cf54-f416-4a11-bc71-d1ac1e8ee85b" x="100" y="0" width="300" height="20"/> <textElement/> <textFieldExpression><![CDATA[$F{t}]]></textFieldExpression> </textField> </band> </detail> <columnFooter> <band splitType="Stretch"/> </columnFooter> <pageFooter> <band height="30" splitType="Stretch"> <textField evaluationTime="Auto"> <reportElement uuid="9235df5b-723e-4e89-9ac7-1c3ba33c807d" x="0" y="0" width="572" height="20" forecolor="#00CC33"/> <textElement textAlignment="Center"> <font isItalic="true"/> </textElement> <textFieldExpression><![CDATA["Page "+$V{currentPage}+" of " + $V{PAGE_NUMBER}]]></textFieldExpression> </textField> </band> </pageFooter> <summary> <band height="30" splitType="Stretch"> <textField> <reportElement uuid="6e98534c-131f-469f-9c4f-dd1de1509da3" x="100" y="0" width="300" height="20" forecolor="#FF0000"/> <textElement> <font isBold="true"/> </textElement> <textFieldExpression><![CDATA["TOTAL NUMBER OF RECORDS PROCESSED: "+$V{REPORT_COUNT}]]></textFieldExpression> </textField> </band> </summary> </jasperReport>
I tested the above report in iReport 5.1 (this version has reached its EOL and is no longer supported) and iReport 5.6 and it works as described in iReport Ultimate Guide.
Posted on May 31, 2016 at 10:53am
For Jaspersoft Studio 6.2, the solution outlined here appears to work.
Create Variable
Create a variable as follows:
- Create a variable called `V_CURRENT_PAGE_NUMBER`
- Select the variable to open its properties (illustrated below)
- Set **Expression** to: `1`
- Set **Initial Value Expression** to: `$V{PAGE_NUMBER} + 1`
- Set **Reset type** to: `Page`
These settings are illustrated in the following figure:
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:
- Select the report in the outline panel
- Check **Summary With Page Header And Footer** to ensure the page footer appears on the summary page.
- Add a **Page Footer** band.
The footer is added.
Create Text Field
Create a text field as follows:
- Drag and drop a *single text field* onto the **Page Footer** band.
- Select the text field.
- Set **Expression** to: `msg("Page {0} of {1}", $V{V_CURRENT_PAGE_NUMBER}, $V{PAGE_NUMBER})`
- Set **Evalutation Time** to: `Auto`
These settings are illustrated in the following figure:
The single text field is created.
Preview Report
For a report with three pages plus a summary page, previewing the report shows:
The summary page shows:
Thanks for the answer Tchen and Hozawa, But this issue happens when there exist a footer for a group, I just made few changes in your sample jrxml and issue still there , Please find below the sample jrxml. you can see in the output that instead of Page Number 3 it is being displayed as page number 2.
Thanks for the modified report to demo this problem. The problem relates to how the variable used to track the current page
was evaluated automatically in the page footer triggerred by the group break-new page condition. Since the group footer happens to be at the bottom of the current page where no available space is left, the group footer section is pushed into a new page. After group footer for the prior group is displayed, the new group starts on a new page. In this special case scenario where a corner/border condition occurs to produce two new pages with one group break-new page, $V{currentPage} is only evaluted once but being displayed twice in two page footer sections, hence demonstrated the behavior as we observed. This looks like a coding defect in JR product.
As it appears, method as discussed in the document only works in a flat report structure due to automatic evaluation for page variables can only keep in syncronization with true page breaks. In your case, you need to use two seperate text fields in order to gain full control over their evaluation time individually in the same page footer section to display "page X of Y" correctly thus avoiding / working around this problem.
Hope this helps to explain the situation.
thanks, tchen ..
I was in vacation ... srry for the delay in response.
we were using two text box solution before, but new requirements says "page X of Y " needs to be right aligned , we could not properly align the two box such a way that the right most text box to be right aligned, if we make it as right most text box as right aligned then there were extra spaces in between and alignments were not proper.