Jump to content
Changes to the Jaspersoft community edition download ×

Tips from a newbie to other newbies


Recommended Posts

By: Gopal - ggopal

Tips from a newbie to other newbies

2005-04-06 15:48

Guys:

 

I finally got the report working and I wanted to post some of the stuff that I had to do to get it done. I spent a considerable amount of time trying to get information. I even posted in this forum while continuing to do my own due diligence. I did not get any replies to my queries.

 

So, what did I have to do to get the report working?

 

Report Design:

---------------------

 

1) I created the report using ireport. 2 things to keep in mind while designing and compiling the reports.

a) Make sure that the tools.jar from your {JAVA_HOME}/lib is copied to the ireport's home/lib directory.

b) Make sure that the jasperreports*.jar (* is the version) is the same in ireport_home/lib and in your classpath of execution.

 

If you downloaded the latest version and you are using it for execution and your reports are compiled using an older version, jasper reports will not work. You will see an error for serialversionUID.

 

2) When you are defining the various fields that will be populated in your java app (creating dynamic reports), make sure that the field name is called as follows:

For the 1st column - Field name = COLUMN_0

2nd column - Field name - COLUMN_1

3rd column - Field name - COLUMN 2 ....

 

or 1st column - Field name = 0

2nd column - Field name - 1

3rd column - Field name - 2 ..... etc...

3) After the report design is completed, compile your report.

 

Java Application

-----------------------

 

1) If you are using an IDE like jbuilder, make sure that you have included the following jar files (tools --> configure -->Libraries, use Add)

a) jasperreports-0.6.6.jar (should be the same verson as ireport jasperreports*.jar)

b) commons-logging.jar (from the jakarta commons lib)

c) commons-logging-api.jar

 

2) If you are loading the details at runtime dynamically, i.e. the report will be filled at runtime when the field values are retrieved/populated ...

for e.g. in my case, I was creating a simple report which consisted of errata for my customer's data. So, it's a typical batch processing where I read 1 record, validate it, format it and write an output record if valid else I create an errata ... In this scenario, I can only get the values of the report fields as and when I have completed the validation.

 

3) I used a jtable to create a multi-dimensional table. Specifically, I used the defaulttablemodel. This allowed me to create he 2 dimensional table and populate it with data. Of course, the added advantage was that I could now include a preview window with few more lines of code.

 

4) After the jtable has been populated and you are ready to create the report, do the following:

 

a) Instantiate net.sf.jasperreports.engine.data.JRTableModelDataSource jrd = new net. sf.jasperreports.engine.data.JRTableModelDataSource( <your defaultablemodel containing data>)

 

b) Instantiate

net.sf.jasperreports.engine.JasperFillManager jfm = new net.sf.jasperreports.engine.JasperFillManager();

 

c) Instantiate

net.sf.jasperreports.engine.JasperPrint jp = new net.sf.jasperreports.engine.JasperPrint();

 

d) Instantiate (optional, only if you want to export to pdf)

net.sf.jasperreports.engine.JasperExportManager jem = new net.sf.jasperreports.engine.JasperExportManager();

 

d) when you pass filename with paths make sure that you escape it porperly e.g. "\" or "/" (nix style)

 

e) Call the fillmanager's fillreport method with source filename (which is the compiled report .jasper extension). This will return a jasperprint object

 

f) to export to pdf, make sure that you have the itext jar in your class path as well ...

 

call the export manager's exportReportToPdfFile method with the destination filename ...

 

and that's it ...

 

The current version of jasper works.

 

Maybe, one of the experts in this forum can answer this question ...

 

1) Why does the JRTableModelDataSource object's getfieldvalue, use the name of the field (created in ireport) as an index and treat it as numeric? I don't get it?

 

I got a numberformat exception when I had field value names like CustNo ..., then when I changed to COLUMN_1 ... of course I got an arrayindexoutofboundsexception .. and when I changed to COLUMN_0, my report worked ...

 

Anyway, that's my 2 cents of information to those people who are struggling with jasper ... It's a great product, but it could do a lot in the area of documentation ...

 

Thanks for reading this rather long post and I hope that it helps someone out there.

 

regards,

-- Gopal

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

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