Jump to content
We've recently updated our Privacy Statement, available here ×

Generation of page numbers in a table of content


simon dark

Recommended Posts

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 to
create 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 of
the 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 used
the break element which functions properly - all elements are placed in a single page. Within the line element a scriptlet's
method 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 elements
Chart1 ........1
Chart2 ........1

In case we have 3 elements
Chart1 ........1
Chart2 ........1
Chart3 ........2

In case we have 4 elements (charts)

Chart1 ........1
Chart2 ........1
Chart3 ........2
Chart4 ........3

etc.

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

  • 4 weeks later...
  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...