simon dark Posted July 23, 2009 Share Posted July 23, 2009 Hallo Jasper developers,I have an issue concerning the generation of page numbers in a table of content.Following the example provided within the /samples/tablesofcontents I am able tocreate a table of contents and everything is fine except for the page numbering.I have a simple master report and a subreport that in fact displays the actual content ofthe report - a collection of charts with a title and a description. Here is a relevant code snippet of the subreport section: <band height="350" isSplitAllowed="false"> <break type="Page"> <reportElement x="0" y="0" width="0" height="0"/> </break> <line> <reportElement x="0" y="0" width="0" height="0"> <printWhenExpression>((net.sim.jaspchart.ReportScriptlet)$P{REPORT_SCRIPTLET}).addEntry($F{title})</printWhenExpression </reportElement> </line>... two text fields (title + description) <image scaleImage="RetainShape" hAlign="Center" vAlign="Middle"> <reportElement x="0" y="90" width="515" height="260" positionType="Float"/> <imageExpression class="net.sf.jasperreports.engine.JRRenderable">$F{chart}</imageExpression> </image></band>Note that each image (and the associated text fields) MUST be placed in an individual page and for this purpose I usedthe break element which functions properly - all elements are placed in a single page. Within the line element a scriptlet'smethod is called (addEntry($F{title})) which constructs a single table of contents' entry and adds it to a collection.Here is the scriptlet's method implementation; public Boolean addEntry(String title) throws JRScriptletException{ Collection<TOCEntry> entries = (Collection<TOCEntry>)this.getParameterValue("tocEntries"); Integer pageNumber = (Integer)this.getVariableValue("PAGE_NUMBER"); TOCEntry tocEntry = new TOCEntry(title, pageNumber, title); return Boolean.valueOf( entries.add( tocEntry) );}Note that each table of content entry has the format (title, page number, reference)The table of contents is constructed properly except for the page numbering which is as follows:In case of 2 elementsChart1 ........1Chart2 ........1In case we have 3 elementsChart1 ........1Chart2 ........1Chart3 ........2In case we have 4 elements (charts)Chart1 ........1Chart2 ........1Chart3 ........2Chart4 ........3etc.I have no clue why Jasper starts to increment the page number after the second and not after the first TOCEntry object was created.This certainly has something to do with the way PAGE_NUMBER is used within a subreport.Any help is deeply appreciated. Link to comment Share on other sites More sharing options...
teodord Posted August 20, 2009 Share Posted August 20, 2009 Hi, Please post the complete JRXML files and the code involved. Also, a PDF with the result you get would be helpful in understanding the problem. Thank you,Teodor Link to comment Share on other sites More sharing options...
alcoholic Posted August 20, 2009 Share Posted August 20, 2009 I've been able to generate a table of content with page numbers in the master report. See if this post can help:http://jasperforge.org/plugins/espforum/view.php?group_id=83&forumid=101&topicid=57374If your requirements are the same as mine and if you face any issues, just reply and I'll elaborate more on the approach I've used . Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now