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

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


narasumas

Recommended Posts

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

  • Replies 16
  • Created
  • Last Reply

Top Posters In This Topic

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

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • 1 year later...

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...

Link to comment
Share on other sites

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

  • 2 months later...
  • 3 years later...

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

 

Link to comment
Share on other sites

  • 9 months later...

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"?>

select * from users

]]></fieldDescription></p><p> </field></p><p> <pageHeader></p><p> <band height="23" splitType="Stretch"></p><p> <textField evaluationTime="Page"></p><p> <reportElement x="120" y="0" width="238" height="20"></p><p> <printWhenExpression><![CDATA[!$V{PAGE_NUMBER}.equals($P{REPORT_PARAMETERS_MAP}</p><p> .get("LastPageNumber"))

"please don't print on last page - page header"

"last page variable is: " + $V{PAGE_NUMBER}.equals($P{REPORT_PARAMETERS_MAP}</p><p> .get("LastPageNumber"))

"Page header"

"last page variable is: " + $V{PAGE_NUMBER}.equals($P{REPORT_PARAMETERS_MAP}</p><p> .get("LastPageNumber"))

$F{userName}

!$V{PAGE_NUMBER}.equals($P{REPORT_PARAMETERS_MAP}</p><p> .get("LastPageNumber"))

"please don't print on last page - detail"

new Boolean($P{REPORT_PARAMETERS_MAP}.put("LastPageNumber",</p><p> $V{PAGE_NUMBER}))

"last page variable is: " + $V{PAGE_NUMBER}.equals($P{REPORT_PARAMETERS_MAP}</p><p> .get("LastPageNumber"))

 

Link to comment
Share on other sites

  • 3 months later...
  • 5 months later...

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...