How to hide Page X / Y when report is 1 page ?

Hello,

I can display "Page X / Y" without any problems, but I also want to hide this "Page X / Y" fields when the generated report is only one page length.

Using <printWhenExpression><![CDATA[$V{PAGE_NUMBER} > 1]]></printWhenExpression> for the corresponding textfields is not working properly : it will always hide the fields on the first page whereas I of course want those fields to be displayed for reports that have more than one page.

In fact, what I need is a way to set  "evaluationTime" to "Report" for the printWhenExpression attribute. Is it possible ?

If not, is there anyway of achieving this otherwise ?

Thanks and regards :)

Code:
			<textField isStretchWithOverflow="false" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self">
				<reportElement x="369" y="42" width="100" height="18" key="textField">
					<printWhenExpression><![CDATA[$V{PAGE_NUMBER} > 1]]></printWhenExpression>
				</reportElement>
				<box/>
				<textElement textAlignment="Right">
					<font/>
				</textElement>
				<textFieldExpression class="java.lang.String"><![CDATA["Page " + $V{PAGE_NUMBER} + " / "]]></textFieldExpression>
			</textField></td></tr></tbody></table>
narasumas's picture
Joined: Oct 2 2008 - 8:29am
Last seen: 14 years 12 months ago

10 Answers:

You could add a dummyline at summary section in negative y value where you put a boolean flag to REPORT_PARAMETER_FLAG in its PrintWhenExpression

e.g..

new Boolean($P{REPORT_PARAMETER_MAP}.put("LastPageFlag",Boolean.TRUE))

 

In your printwhenexpression you must get this value and compare it against true.

Something like this:

new Boolean(!(Boolean.TRUE).equals($P{REPORT_PARAMETER_MAP}.get("LastPageFlag")))

 

(not tested but I did something similiar in former times when using carry overs)

hth

C-Box

C-Box's picture
24067
Joined: Jul 19 2006 - 5:58pm
Last seen: 4 weeks 13 hours ago

Thanks a lot to C-Box, im spending a lot of time for finding a way to check is current page is a last page or not in the jasperreport expression.

step-by-step - 8 years 6 months ago

Thanks for the help :)

I don't really understand your solution... You are suggesting to add a summary and set a "isLastPage" variable within this summary section, correct ? As the summary is always in the last page, I would just need to check if isLastPage variable is true before displaying my Page X/Y. I'm not sure that is what you were suggesting... But anyway I don't know how to set and get this isLastPage variable...

Maybe you could be more specific ? :)

PS : It would have been far simpler if we just had a variable always containing the total number of pages of the report...

narasumas's picture
Joined: Oct 2 2008 - 8:29am
Last seen: 14 years 12 months ago

Well it's difficult to explain and something similiar was at the Jasper Tipps and Tricks page some years ago... so I have it just in mind as I can't find the Jasper explanation of this trick at the new homepage.

 

But as I have had some free minutes right now. I do build you a sample.

Just look at the JRXML ... there is a line at Summary section, where I put the LastPageNumber into the Report-Parameter-Map.

 

At the normal PageFooter I just print the Page X / Y when the current PageNumber is not the LastPageNumber or if the PageNumber is bigger than 1 (to show it also at last page).

 

I do attach some PDFs also to show how it works. Just try it out with iReport and run it without data (first PDF) and then with 100 dummy records (press shif while pression the blue button and enter 100) and see the result (second PDF)

 

hth

C-Box

C-Box's picture
24067
Joined: Jul 19 2006 - 5:58pm
Last seen: 4 weeks 13 hours ago

Ups... seems that the forum doesn't support such long file names...

I do attach the PDFs again...

 

regards

C-Box

C-Box's picture
24067
Joined: Jul 19 2006 - 5:58pm
Last seen: 4 weeks 13 hours ago

Hey CBox,
i have the discussed problem and it seems that your uploaded PDF file is not longer avbliable.
Could you please upload the file again?
Thanks a lot

wandl - 9 years 1 week ago

CBox
Wrote:

Well it's difficult to explain and something similiar was at the Jasper Tipps and Tricks page some years ago... so I have it just in mind as I can't find the Jasper explanation of this trick at the new homepage.

 

But as I have had some free minutes right now. I do build you a sample.

Just look at the JRXML ... there is a line at Summary section, where I put the LastPageNumber into the Report-Parameter-Map.

 

At the normal PageFooter I just print the Page X / Y when the current PageNumber is not the LastPageNumber or if the PageNumber is bigger than 1 (to show it also at last page).

 

I do attach some PDFs also to show how it works. Just try it out with iReport and run it without data (first PDF) and then with 100 dummy records (press shift while pressing the blue button and enter 100) and see the result (second PDF)

 

hth

C-Box

C-Box's picture
24067
Joined: Jul 19 2006 - 5:58pm
Last seen: 4 weeks 13 hours ago

Hi, How can i download your pdf file?

Thank you

hadv - 10 years 1 month ago

Thanks !

I have tried your solution and it's working great !

Thanks for the help :)

narasumas's picture
Joined: Oct 2 2008 - 8:29am
Last seen: 14 years 12 months ago

Hi,

How did you do? I need it urgently; so could you please explain me more details?

Thank you

hadv - 10 years 1 month ago

Hi,

I'm facing the same problem now and I tried your solution and it works... but not in my case. I need to check for the last page in the "background" band and in this case it does not work anymore. Even if I modify your example by moving the TextFields to the "background" band, it stops working. Any idea why is that and how I could fix it? Or how I could detect the last page in a different way?

 

And please don't tell me not to use "background" band. I have a really complicated case of reports with subreports and now I have to add a common information on all pages (no matter which subreport they come from) but the last one. "Background" seems perfect for this... except the detection of the last page. Please help...

stelek's picture
234
Joined: Dec 11 2009 - 5:59am
Last seen: 13 years 9 months ago
Seems the problem is with the "evaluation time". If I change it from "now" to "page" it starts working but of course in this way you can only affect the content of the field and not its visiblity. I'll appreciate any other ideas...
stelek's picture
234
Joined: Dec 11 2009 - 5:59am
Last seen: 13 years 9 months ago

Yep, I found the same problem.

It's only have value when using the "evaluation time' as "report"; but the expression in printWhen be always evaluated "now"

Do you have any solution for it?

Thank you

hadv - 10 years 1 month ago

I need to hide the page header band on the last page and I am facing this same problem. in this example, you see that the variable value changes as expected with evalaution time of page. but the printWhen for the band and for fields is not effected. Any ideas?:

<?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="report3" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<queryString>
<![CDATA[select * from users]]>
</queryString>
<field name="userName" class="java.lang.String">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<pageHeader>
<band height="23" splitType="Stretch">
<textField evaluationTime="Page">
<reportElement x="120" y="0" width="238" height="20">
<printWhenExpression><![CDATA[!$V{PAGE_NUMBER}.equals($P{REPORT_PARAMETERS_MAP}
.get("LastPageNumber"))]]></printWhenExpression>
</reportElement>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA["please don't print on last page - page header"]]></textFieldExpression>
</textField>
<textField evaluationTime="Page">
<reportElement x="380" y="0" width="175" height="20"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA["last page variable is: " + $V{PAGE_NUMBER}.equals($P{REPORT_PARAMETERS_MAP}
.get("LastPageNumber"))]]></textFieldExpression>
</textField>
<textField>
<reportElement x="2" y="2" width="100" height="20"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA["Page header"]]></textFieldExpression>
</textField>
</band>
</pageHeader>
<detail>
<band height="21" splitType="Stretch">
<textField evaluationTime="Page">
<reportElement x="381" y="0" width="174" height="20"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA["last page variable is: " + $V{PAGE_NUMBER}.equals($P{REPORT_PARAMETERS_MAP}
.get("LastPageNumber"))]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="0" width="100" height="20"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{userName}]]></textFieldExpression>
</textField>
<textField evaluationTime="Page">
<reportElement x="119" y="0" width="191" height="20">
<printWhenExpression><![CDATA[!$V{PAGE_NUMBER}.equals($P{REPORT_PARAMETERS_MAP}
.get("LastPageNumber"))]]></printWhenExpression>
</reportElement>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA["please don't print on last page - detail"]]></textFieldExpression>
</textField>
</band>
</detail>
<lastPageFooter>
<band height="50">
<line>
<reportElement x="188" y="21" width="100" height="1">
<printWhenExpression><![CDATA[new Boolean($P{REPORT_PARAMETERS_MAP}.put("LastPageNumber",
$V{PAGE_NUMBER}))]]></printWhenExpression>
</reportElement>
</line>
<textField evaluationTime="Page">
<reportElement x="380" y="2" width="174" height="20"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA["last page variable is: " + $V{PAGE_NUMBER}.equals($P{REPORT_PARAMETERS_MAP}
.get("LastPageNumber"))]]></textFieldExpression>
</textField>
</band>
</lastPageFooter>
</jasperReport>

tomkast_1 - 9 years 3 months ago
Did you solve this? I'm trying to figure it out now myself.

Thanks
jwindberg's picture
1600
Joined: Nov 9 2006 - 1:29am
Last seen: 16 years 10 months ago

I finish this problem with java code like moving the table of content from the last page to the first page of the report

 

hadv's picture
65
Joined: Sep 3 2012 - 8:51pm
Last seen: 5 years 9 months ago
Feedback
randomness