I'm new to Jasper reports and currently I'm in creation of some reports using Jasper version 3.7.3. My report contains header, detail and footer sections. The header, footer and detail sections are all subreports.
The problem is, I can't able to generate the proper page number as "current page number" of "total pages" when I use the page number variable in the footer subreport with any evaluation time.
Is there any I way I can acheive this page number display properly in the footer subreport.
Thanks in advance.
I am also facing the same problem. When we add Page X of Y component in subreport, the value of Y gets populated at the end of the subreport. There should be some way by which it will get populated at the end of main report and not at the end of subreport.
Thanks in Advance.
Hi, Thanks for your reply.
But I didn't understood your approach completely.
As I understood, you are saying there will be two 'page x of y' components. One in master report and one in subreport. And I should hide one of them based on some condition.
There are few problems:
- I have to put both the components at the same position, in this case my subreport will always ovrwrite component from master report.
- I have lots of other things apart from component in the subreport, so if I didn't print subreport nothing from the subreport will get printed.
Can you please elaborate more on your approach.
Post Edited by kiranbhuse83 at 12/01/2011 09:02
I'll try to be more detailed: the 'page X of Y' control in the iReport pallette consists in 2 related textfields with some predefined properties helpful for calculating page numbers.
If you intend to use the footer subreport as standalone report too, then the 'page X of Y' control in the subreport is completely justified, but you need to show it only when the report is used as standalone report, and it should be hidden when the report is used as subreport. In this condition a printWhenExpression could be used to avoid printing the 'page X of Y' control in the subreport (in the printWhenExpression you could check for the presence of a parameter from the master report, for example). In this case, the best place for the 'page X of Y'control is in the master report. It will not be overriden by the 'page X of Y' of the subreport, because this one won't be printed at all.
If you need to use the footer subreport as subreport only, then the 'page X of Y'control is no more needed in the subreport, you can remove it. Again, the best place for the 'page X of Y'control is in the master report.
Hope this helps,
Thanks for all you replies.
Anyhow our intention is not to use footer as a standalone report. Anyway it is going to be a subreport and part of the main report in the footer section.
As per the reply, it looks like we need to have two 'page x of y' components, one at the main report and one in the subreport as in the same position, but to hide the one in the subreport based on a parameter condition from main report.
There comes the dependency, the main objective of using the footer as a subreport is reusability of the same across all the other main reports. If we need to use it in both main and footer subreport, all the other main reports get impacted by placing the 'x of y' component in every main report.
Hope our requirement is clear now, is there any possiblities we can achieve this in Jasper?
I would say that the 'page X of Y' control is not reusable this way. It will count only pages in the enclosing subreport, and the main report can still continue after all pages in the subreport are rendered.
At the moment there's no possibility to determine the total number of pages of the main report from a given subreport. Or at least I don't know about such a possibility. Only in the main report we get the entire information about the total number of pages, so we have to use the 'page X of Y' here and not in the subreport, although this means that each main report should have its own the 'page X of Y'control. In this case the reusability is less important than the accuracy of the result.
To summarize this, try to completely remove the 'page X of Y' from the subreport and place it in the main report instead. See if it solves the problem.
Post Edited by shertage at 12/05/2011 10:13
we use JR for many years from version 0.5.3 (when I remember right)... the TOTAL_PAGE_NUMBER usage in subreports was discussed often in forum and we actually would need it also (as we also have just ONE global formfooter /-header designed as a subreport) ... but as the variable PAGE_NUMBER is calculated at each (sub)report level individually there wasn't and isn't any chance to achieve this with "normal" JR usage...
But it's JR... so it's quite flexible.... just add an property or a key (e.g. "MyTotalPageNumberField") to your TOTAL_PAGE_NUMBER field... after the report has finished just count the pages of resulting JasperPrint Object ... so you have the resulting number of total pages...
now loop through every page, parse the elements for your "MyTotalPageNumberField" and replace the content like
and voilà you got it....
we do something similiar with numbering the copy printouts... so that each copy that is passed to the printservice gets its own text like "COPY X/Y".... it's very fast and better than recall the report for every copy printout with a parameter...
so as you see... JR is what you want! Just be creative!!!
hth + regards from Germany