[ACCEPTED]-Compare current page number with last page number-jasper-reports

Accepted answer
Score: 18

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

First 5 in your summary band put this line

<printWhenExpression><![CDATA[new Boolean($P{REPORT_PARAMETERS_MAP}.put("LastPageNumber",$V{PAGE_NUMBER}).equals("dummyPrintWhen"))]]></printWhenExpression>

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

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

For Example

<printWhenExpression><![CDATA[new Boolean(!$V{PAGE_NUMBER}.equals($P{REPORT_PARAMETERS_MAP}.get("LastPageNumber")))]]></printWhenExpression>
Score: 3

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

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

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

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

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

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

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


Score: 2

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

<![CDATA[new Boolean($P{REPORT_PARAMETERS_MAP}.put("LastPageNumber",$V{PAGE_NUMBER}).equals("dummyPrintWhen"))]]></printWhenExpression>

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

you 7 should reverse like this

<![CDATA[new Boolean("dummyPrintWhen".equals($P{REPORT_PARAMETERS_MAP}.put("LastPageNumber",$V{PAGE_NUMBER})))]]></printWhenExpression>

the workaround i 6 used on this question is the following.

1). create 5 a parameter in jasperreports

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

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


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

component print when expression


and prints in 1 the last page.

More Related questions