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)
Related
I have a JasperReport named 'Receipt' that can be launched as a:
subreport in a Summary band, to display any receipts
main report, to display a particular receipt
How can I start a new page before any receipts, when it is used as a subreport, but suppress the new page if there are no receipts?
Setting isTitleNewPage="true" works when it is used in the subreport case, but causes the Detail band to be displayed on the second page when it is used as a main report.
Using a Break prior to the subreport means a redundant page is used if there are no receipts.
I solved it by:
Adding a Boolean isSubReport parameter to the report
in the Detail band, adding a Break, with a Print When Expression set to:
$V{PAGE_NUMBER} == 1 && $P{isSubReport}
In the parent report, passing the parameter isSubReport with value TRUE()
Feels like there should be a cleaner solution, but it seems to work.
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.
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 using JasperReports applied to my web application
I wanna put new page every time my date filed $F{date} change
I already tried drag break element with page break option from palette of iReport and drop it onto filed ->($F{date})
But nothing happened
please give me any advise or solution
Create two variables (in this order):
1. var_date_prev = $V{var_date}
2. var_date = $F{date}
Varibles are evaluated in order in which they are declared so var_date_prev will have date value from previous row.
Add property net.sf.jasperreports.export.xls.break.after.row on field after which you want to make page break and set the expression for the property
$V{var_date_prev} != null && $V{var_date_prev} != $V{var_date}
Is it possible to implement Table of contents with page number on first page of the PDF report?
I've read the below links and refered in google:
1) http://community.jaspersoft.com/questions/541300/table-contents-ireport
2) http://community.jaspersoft.com/questions/529040/generation-page-numbers-table-content
On first link, They are using scriptlets for this. I want Table of contents with page number on the first page of pdf report. But I do not understand where to start. Any ideas?
I would recommend you checking this sample from the original documentation.
There is no way (or at least I don't know/haven't found how) to generate the Table of Contents at the beginning (since there is no way to know the pages numbers). So you will have to generate it at the end (in the summary band) and move it afterwards to where you want to place it. To move it use JasperPrint class, methods getPages, addPage, removePage.
I guess you will have subreports, if so, you need to pass the JRBeanCollectionDataSource you will be filling during runtime to each subreport (and return the value back to the master report).
Hope that helps.