Jump to content
We've recently updated our Privacy Statement, available here ×

Printing Page X of Y in a Single Textfield logic in Jasper Ultimate Guide section 19.2.2 is breaking


shanid25

Recommended Posts

 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.
 
Link to comment
Share on other sites

  • Replies 7
  • Created
  • Last Reply

Top Posters In This Topic

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 tunion allselect 2 as n, 'two records.' as tunion allselect 11 as n, 'This page has' as tunion allselect 12 as n, 'three records.' as tunion allselect 13 as n, '******' as tunion allselect 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>[/code]

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.

Link to comment
Share on other sites

I've tested on Jaspersoft Studio 6.1.0 and all works well. Used the sample database with "SELECT * FROM ORDERS". Group by Customerid and only put $F{CUSTOMERID} in CUSTOMERID Group Footer. Added to print page number in page footer. All works as expected.

 

Link to comment
Share on other sites

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.

<?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, 'three records.' as t                     union all                     select 14 as n, 'three records.' as t                     union all                     select 21 as n, 'This page has one record' as t]]>        </queryString>        <field name="t" class="java.lang.String"/>        <field name="n" 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[(Integer.valueOf($F{n})).intValue()/10]]>            </variableExpression>        </variable>        <group name="groupA" isStartNewPage="true">            <groupExpression>                <![CDATA[$V{groupA}]]>            </groupExpression>            <groupFooter>                <band height="50">                    <textField>                        <reportElement uuid="6e98534c-131f-469f-9c4f-dd1de1509da3"                                       x="100" y="16" width="300" height="20"                                       forecolor="#FF0000"/>                        <textElement>                            <font isBold="true"/>                        </textElement>                        <textFieldExpression>                            <![CDATA["TOTAL NUMBER OF RECORDS PROCESSED: "+$V{REPORT_COUNT}]]>                        </textFieldExpression>                    </textField>                </band>            </groupFooter>        </group>        <background>            <band splitType="Stretch"/>        </background>        <title>            <band splitType="Stretch"/>        </title>        <pageHeader>            <band splitType="Stretch"/>        </pageHeader>        <columnHeader>            <band height="183" splitType="Stretch">                <staticText>                    <reportElement uuid="e9eba606-0d40-4bcc-91d4-e22840dc8bf0"                                   x="0" y="0" width="100" height="156"/>                    <textElement/>                    <text>                        <![CDATA[Record ID]]>                    </text>                </staticText>                <staticText>                    <reportElement uuid="7b977850-d1f4-45bd-9bf4-fc02d20d133e"                                   x="100" y="0" width="300" height="156"/>                    <textElement/>                    <text>                        <![CDATA[Text]]>                    </text>                </staticText>            </band>        </columnHeader>        <detail>            <band height="130" splitType="Stretch">                <textField>                    <reportElement uuid="b897c39c-5173-4d46-a209-d160dcbd1470"                                   x="0" y="0" width="100" height="115"/>                    <textElement/>                    <textFieldExpression>                        <![CDATA[$F{n}]]>                    </textFieldExpression>                </textField>                <textField>                    <reportElement uuid="3709cf54-f416-4a11-bc71-d1ac1e8ee85b"                                   x="100" y="0" width="300" height="115"/>                    <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"/>        </summary>    </jasperReport>[/code]

 

Link to comment
Share on other sites

Thanks for the modified report to demo this problem. The problem relates to how the variable used to track the current page

    <variable name="currentPage" class="java.lang.Integer" resetType="Page">        <variableExpression><![CDATA[$V{PAGE_NUMBER}]]></variableExpression>    </variable>[/code]

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.

    <pageFooter>        <band height="30" splitType="Stretch">            <textField evaluationTime="Page">                <reportElement x="0" y="0" width="286" height="20" forecolor="#00CC33" uuid="989ed34e-7b28-4270-b495-110385990610"/>                <textElement textAlignment="Right">                    <font isItalic="true"/>                </textElement>                <textFieldExpression><![CDATA["Page "+$V{PAGE_NUMBER}+" o"]]></textFieldExpression>            </textField>            <textField evaluationTime="Report">                <reportElement x="286" y="0" width="286" height="20" forecolor="#00CC33" uuid="de370573-b40c-40e1-b7fe-21f61ffb69f8"/>                <textElement textAlignment="Left">                    <font isItalic="true"/>                </textElement>                <textFieldExpression><![CDATA["f " + $V{PAGE_NUMBER}]]></textFieldExpression>            </textField>        </band>    </pageFooter>[/code]

Hope this helps to explain the situation.

 

Link to comment
Share on other sites

  • 2 weeks later...

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.

 

 

 

 

Link to comment
Share on other sites

  • 4 months later...
  • 5 months later...
For Jaspersoft Studio 6.2, the solution outlined here appears to work.

 

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} + 1`
  5. 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:

 

  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:

 


 

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:

 


 


Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...