Ohhh Yeahh!
2 Weeks of Headdaches for that Table of Content Thing.
First of all, you need a Java Class to Store your Data for the Table of Content:
package bewerberhandoutapp;
import java.io.Console;
import java.lang.System;
public class HeadingBean
{
private String headingText = null;
private Integer pageIndex = null;
public HeadingBean(
String text,
Integer pageIndex
)
{
this.headingText = text;
this.pageIndex = pageIndex;
}
public String getHeadingText()
{
return this.headingText;
}
public Integer getPageIndex()
{
return this.pageIndex;
}
}
Then you need a class where you are creating Objects of your Data.
public class HeadingScriptlet extends JRDefaultScriptlet
{
public Boolean addHeading() throws JRScriptletException
{
Integer kontaktid = (Integer)this.getFieldValue("KontaktId");
Collection headings = (Collection)this.getVariableValue("HeadingsCollection");
String vorname = null;
String nachname = null;
String anrede = null;
String titel = null;
String name = null;
String insertname = null;
Integer pageindex = (Integer)this.getVariableValue("PAGE_NUMBER");
vorname = (String)this.getFieldValue("Vorname").toString().trim();
nachname = (String)this.getFieldValue("Nachname").toString().trim();
anrede = (String)this.getFieldValue("Anrede").toString().trim();
titel = (String)this.getFieldValue("Titel").toString().trim();
name = anrede.trim() + " " + titel.trim() + (titel.equalsIgnoreCase("") || titel.equalsIgnoreCase(null) ? "" : " ") + nachname.trim() + ", " + vorname;
insertname = (String)name;
try
{
headings.add(new <packageName>.HeadingBean(insertname, pageindex));
}
catch (Exception e)
{
System.out.println(e);
}
public String Caller() throws JRScriptletException
{
addHeading();
String ausgabe = null;
return ausgabe;
}
}
}
= the name of your *.jar
Compile these 2 classes.
in iReport:
Include the jar file you created to the classpath of iReport.
Add in the Properties of your Report the scriptlet class:
.HeadingScriptlet
Now you need to declare a variable.
Call it:
HeadingsCollection
its of type:
java.utils.collection
initial value:
new java.util.ArrayList()
calculation:
system
Create a subreport in the summary band.
Connection Type of the subreport:
Use a datasource expression
Datasource expression is:
new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($V{HeadingsCollection})
In the subreport, you click on the SQL Button.
There you have to go to the JavaBean Datasource Tab.
In the first name you put your package and class Name.
eg.
.HeadingScriptlet
Then iReport should show you the Properties of your class.
In our case:
pageIndex
headingText
These Two fields you can use just like a normal field.
Back to the Main Report:
Add a field of type String to your report, where you actually want to push your data to the Bean.
In that field you have to write:
$P{REPORT_SCRIPTLET}.Caller()
Run your Report.
I hope i didnt forget any steps ![Smile :)]()
Have fun while sorting it out. I had lots of it! ![Twisted Evil :twisted:]()
Greets
Jan