Compare current page number with last page number

匿名 (未验证) 提交于 2019-12-03 08:36:05

问题:

How do you check to see if the current printed page is actually the last printed page?

I have tried the following:

$V{currentPage}.intValue() == $V{totalNumberOfPages} ?   Boolean.TRUE : Boolean.FALSE 

回答1:

waited for a long time .. but no reply from Stackoverflow... Anyway i found my solution..

First in your summary band put this line

Remember this above line must be only in the summary band of the report.

After that you can compare this parameter at any point of time in your report to find last page number .

For Example



回答2:

With the following Print When Expression the summary band gets printed again:

new Boolean(($P{REPORT_PARAMETERS_MAP}.put( "LastPageNumber",$V{PAGE_NUMBER}).equals("dummyPrintWhen")) || Boolean.TRUE) 

You can also use containskey tot test for the existance of the key:

new Boolean(!$P{REPORT_PARAMETERS_MAP}.containsKey("LastPageNumber")) 

Nummeric expressions also work, this expression evaluates to true on every page except the one on which the parameter is set:

new Boolean($P{REPORT_PARAMETERS_MAP}.get("LastPageNumber") 

My problem was that I created multiple group footers for several crosstabs at the end of my report, with a constant as the group expression so they get printed only once. By setting the parameter in the first footer I can now finally surpress the column headers without resorting to subreports. Great work!!

Berry.



回答3:

unfortunately your approach didn't worked for me i dont know why.. there are some stuff about your code that are error-prone like this

 

i think in fact that the Summary Band is called only once but you have a bad programming practice in this because if there is not key associate with the KEY in the MAP it will return null and the you call the method equals on it you would receive NULLPOINTEREXCEPTION but i think not in this case.

you should reverse like this

 

the workaround i used on this question is the following.

1). create a parameter in jasperreports

parameter name="totalRecordsOnReport" class="java.lang.Integer" 

2). pass the totals records of your detail as parameter.

HashMapparameters=.... parameters.put("totalRecordsOnReport",yourDetailRowCount); 

i need to print some stuff only in the last page below the detail and i use this code.

component print when expression

$V{REPORT_COUNT}.equals($P{totalRecordsOnReport}) 

and prints in the last page.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!