Jump to content

Table of Contents


Recommended Posts

By: Andrew Arrow - andrewarrow

Table of Contents

2002-07-30 10:07

I'm doing the page i of n trick and it works great! But I need to display a table of contents at the begining with the correct page # of each section of the report. For example:

 

Table of Contents:

 

1. Section ABC page 1

2. Section XYZ page 14

3. Section 123 page 17

4. Section NNN page 22

5. Section BBB page 30

 

How can I store these page numbers in variables and use them again later? I have a master report with 13 subreports. The footer of the master report has the $V{PAGE_NUMBER} stuff. The 2nd subreport is the table of contents. I guess scriplets would be the way to go? Have 13 variables and set each after each section's page number is known. But how will I know it's the start of a section and not the middle?

 

 

By: David Sachs - dsach1w

RE: Table of Contents

2002-07-31 10:34

Andrew,

 

This is something I had been wondering about--glad to see you found a solution.

 

I'm relatively new to JasperReports, so I'm trying to come up the learning curve.

 

I'd love to take a look at how you solved this problem. Would it perhaps be possible to post your scriptlet code/report example? Personally, I think a TOC is a very useful feature, and should be one of the standard JasperReports examples on the website.

 

Thanks very much,

 

David

 

 

By: Andrew Arrow - andrewarrow

RE: Table of Contents

2002-07-30 20:59

I have this Scriptlet now and it correctly sets the page # each section starts on. (Since each section triggers a new group, turning the boolean on in afterGroupInit and off in afterPageInit works great.) So I call this.setVariableValue("sPage1", "1") and this.setVariableValue("sPage2", "5") etc. and they all get set correctly. But now how do I display these in the table of contents? In the master.xml I have 15 of these:

 

<variable name="sPage1" class="java.lang.String" resetType="Report" calculation="System"/>

 

And then I tried two methods to get these variable into the sub-report that master.xml calls...

 

<subreportParameter name="sPage1"><subreportParameterExpression>$V{sPage1}</subreportParameterExpression></subreportParameter>

 

but that didn't work. They all show up as null. Then I tried not passing in parameters but rather just re-defining the variables in the sub-report xml. Since they are type "Report" i thought they might be global. Again, they come back as null.

 

When I display the variables in a textfield I use:

 

<textField evaluationTime="Report">

 

but this isn't helping is it? Is there anyway to do this? Am I on the right path? Thanks.

 

 

// Scriptlet Code:

 

public class PageNumberScriptlet extends JRDefaultScriptlet

{

 

boolean on=false;

int index=1;

 

public void afterPageInit() throws JRScriptletException

{

if (on)

{

System.out.println("call afterPageInit : PAGE_NUMBER = " + this.getVariableValue("PAGE_NUMBER"));

 

this.setVariableValue("sPage"+index, this.getVariableValue("PAGE_NUMBER")+"");

index++;

 

on = false;

}

}

 

public void afterGroupInit(String groupName) throws JRScriptletException

{

on = true;

}

}

 

 

 

By: Teodor Danciu - teodord

RE: Table of Contents

2002-08-05 04:14

 

Hi,

 

Unfortunately, the subreports do not have such

a high degree of integration with the main report.

For example, you cannot use main report variables

in the subreport. You can only pass in their value

as parameters at subreport filling stage.

But this way you don't have the right value since

at subreport filling moment the variable value is

not final and correct.

 

I'll think about it and maybe come up with

a trick for you.

 

Thank you,

Teodor

 

 

 

By: Andrew Arrow - andrewarrow

RE: Table of Contents2

2002-07-31 08:42

Found a solution in case anyone else cares....

 

I just took the Table Of Contents out of it's subreport and put it directly into the master.xml. That way all the variables work fine and the evaluationTime of Report does the trick. It was that accessing vars defined in Master down in a sub-report that wasn't working.

 

 

 

 

By: Teodor Danciu - teodord

RE: Table of Contents2

2002-08-05 04:18

 

Hi,

 

I'm glad you found your solution.

 

First I thought about suggesting you this approach.

 

For everybody wanting to use "Table of contents",

I think I'll provide a sample.

 

Thank you,

Teodor

 

 

 

By: Andrew Arrow - andrewarrow

RE: Table of Contents4

2002-08-05 17:00

Sorry for the delay David... I can't very easily paste my example here. (It's so complicated and mixed in with everything else.) After our deadline is over I'll try and seperate the TOC logic into a seperate example... but it looks like Teodor is gonna beat me to this anyways.

Link to comment
Share on other sites

  • 2 years later...
  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

  • 8 months later...

Hi guys,

 

You are adding up to a thread that is 7 (seven) years old and was migrated from the old Sourceforge.net forums.

Andrew is not receiving your messages, unless you write him directly on his Sourceforge.net account.

Many things have happened in the last 7 years, including me sticking to my promise and providing a sample for table of contents.

 

You can find it in the /demo/samples/tableofcontents folder of the JasperReports project distribution package.

 

Thank you,

Teodor

 

Link to comment
Share on other sites

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...