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
waited for a long time .. but no reply from Stackoverflow...
Anyway i found my solution..
First in your summary band put this line
<printWhenExpression><![CDATA[new Boolean($P{REPORT_PARAMETERS_MAP}.put("LastPageNumber",$V{PAGE_NUMBER}).equals("dummyPrintWhen"))]]></printWhenExpression>
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
<printWhenExpression><![CDATA[new Boolean(!$V{PAGE_NUMBER}.equals($P{REPORT_PARAMETERS_MAP}.get("LastPageNumber")))]]></printWhenExpression>
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") < $V{PAGE_NUMBER})
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.
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
<![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 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
<![CDATA[new Boolean("dummyPrintWhen".equals($P{REPORT_PARAMETERS_MAP}.put("LastPageNumber",$V{PAGE_NUMBER})))]]></printWhenExpression>
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.
HashMap<Object,Object>parameters=....
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.
Related
How can I achieve this? I also tried using "print when expression" with condition
new Boolean($V{PAGE_NUMBER}.intValue() < $V{PAGE_COUNT}.intValue())
but sadly it does not work. Please help me.
This print when expression works fine for me $V{PAGE_NUMBER}<$V{PAGE_COUNT}. It works when applied to either the column footer band or the footer band element (I used static text).
Comparing PAGE_NUMBER and PAGE_COUNT is like comparing apples and oranges.
The Built-In Variables
PAGE_NUMBER: At every iteration it contains the number of the pages that compose the report.
PAGE_COUNT: Contains the number of record processed in the current page
To answer the question: JasperReports knows a band type "Last Page Footer" (wiki description) to define a different footer on the last page.
(Your problem might already be solved. But I stumbled upon this two year old question while having a similar issue and wanted to leave a hint, that one should not compare those variables.)
I am trying to do a simple expression in iReport, but whatever I try seems hasn't given me which I expected. It seems like such a simple thing to do, but I couldn't understand what's happening with my code.
All I'm trying to do is show a subreport when the value of an string field is a simple word like "VALUE". I am using the Print When Expression for the subreport control, however I'm not able to the see or reproduce this text with this expression. For me seems that I'm not passing well the parameters I wan't to use to do the print when expression in the subreport from the master report.
Is a disclaimer, so in master report I have a simple subreport, with the same conection from master and one parameter called Entity = "_id.Entity" (we use mongodb to get the fields for the report with a $group) and in the subreport part I have 2 text fields, the first one have the print when expression when P{Entity}.equals("VALUE"), the second one don't have any condition so this works perfectly, but the textfield with the condition doesn't work.
Any help would be appreciated. Thanks.
I have a jasperreport that prints debtors statements. I need to print 'Continued on the next page' in place of my existing group footer when there are more records than can fit on the first page.
I have created a second group footer which has the message and I want to print this when there is more to print, and the existing when it has finished.
Is there a way I can tell, at the end of the page, if there are more records in the group to print so I can build a "Print with Expression" expression?
With thanks
Mark
Ok this is the way I solved this.
I moved my subtotals for each client to the Page Footer and I added a text field with the words 'Continued...'.
In my group footer I placed a subreport component. I created a Boolean var called returnValue and passed it to and back from the subreport which set it false.
Using the print expression I only print the subtotal fields when returnValue is false and the 'Continue...' field when it tests null.
I am using iReport version 4.0.1. I am facing a problem in which I want to display some information that must come on the 2nd page only. So, its neither a FOOTER nor a LAST-PAGE-FOOTER. I am using iReport for generating the jrxml files and the design looks something like below.
{HEADER}
{DETAIL-BAND-1} Remarks: Till this point my 1st page finishes
{DETAIL-BAND-2} Remarks: This is coming from a sub-report
{DETAIL-BAND-3} Remarks : This is coming from a sub-report
Some Random Empty Space Is Left
{DETAIL-BAND-4} Remarks: This is where my 2nd page footer needs to come.
.
.
.
.
{Lots of Bands}
.
.
{MAIN-REPORT-FINISHES}
So, I want the footer (actually it is not a footer, its some detail that only need to come on the 2nd page of the pdf generated by JR) to be fixed relative to the top of the page in which it is being printed. Is there a way to do that?
Thanks
Try to use the property "Print When Expression" and then you can use a variable that already exists in your iReport called PAGE_COUNT and it will be printed only when this expression is true.
I have to prepare a letter in which I require a 40 mm page header for first page and 20mm page header for all other pages except the first page. So I've created 2 page headers.
I want to hide/show the page headers based on the page number.
But when I write the following print when expression, it doesn't work.
$V{PAGE_NUMBER}.equals("1")
You need to check what the type of $V{PAGE_NUMBER} is... (I think it is java.lang.Integer)
The method you choose return a boolean an a PrintWhenExpression should return a java.lang.Boolean, so you need to instantiate one.
Try :
new Boolean($V{PAGE_NUMBER}.equals("1"))
It should work... To improve your test, I think that it is better to make a int comparison (a Java specialist should confirm that)
new Boolean($V{PAGE_NUMBER}.intValue() == 1)
The other manipulation you might have to do is specifying the whole object name (I don't know how JasperReport deals with import)
new java.lang.Boolean($V{PAGE_NUMBER}.intValue() == 1)