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

How to implement external pagination?


lazybee26

Recommended Posts

I'm new to Jasper Reports and haven't tried any code yet.  I'm just trying to read and understand the capabilities, before I dive in.

Problem definition
I want to understand how I can implement external pagination using Jasper Reports. FYI I have read about virtualizer, printobjects a little bit.

Example using simple webapp
Lets say I have a customer table, with 1 million records.  I want to simply display the list of customers, with 1000 records per page.  So I have 1000 pages, with 1000 records on each page.
If I implement this in a standard web application, I will first figure out number of records in customer table and decide number of pages depending on records per page (1000) etc...  On the UI side, I'll have navigation buttons like Next, Previous, Start, End.  Depending on what user clicks, I can figureout the page number and accordingly, only query 1000 records from the customer table, for that specific page.  In this scenario, I have control over the clicks and know exactly the page user has requested.  So my resultset will always have only 1000 records retrieved from database for display.  So this way I can implement external pagination in a plain vanilla webapplication.

.........Now how do I do this in JasperReports?

 


I read about Virtualizer and PrintObject.  My understanding is that the virtualizer will get all the results, in chunks to avoid outofmemory exception and feed it to printobjects.  So in my example, it'll get all 1 million records and feed them to printobjects.  Once printobjects are created, the information can be displayed to the browser.
When user clicks next or previous, the printobject can be accessed from session and so the db is not queried again.

BUT, what if I only want the records of the specific page to be retrieved (which is 1000 records), instead of getting all 1 million records.


Unfortunately I've understood the functionality only half way....I need to write code to get a better understanding.

Regardless, I thought I'll throw this question out there, just to get some direction.
 

Again, I want to figureout how to implement external pagination in jasper reports. As another example, lets say I have to generate a crosstab report using JasperReport, that has like 40,000 records to process, whats the best way to implement it such that the output is fast and gets data only for the specific page?  Example - Display zipcodes of cities in each state of United States, where state is a row, city is column and cell has the zip code.

 

 

Thanks
Amit
 



Post Edited by lazybee26 at 09/14/2010 05:40
Link to comment
Share on other sites

  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Hi,

Yes, it is possible to implement pagination, even for very large reports, using report virtualizers and the JRExporterParameter.PAGE_INDEX export parameter.

In order to get some useful hints on howto accomplish this, you could take a look at both virtualizer and webapp samples provided with the JR package distribution. The first one shows how to fill a report using virtualizers. Try to run the webapp sample from within a Tomcat server, and you'll see the pagination at work if you choose "JSP Page By Page Viewer" in the "export report" section.

Hope this helps,

sanda

Link to comment
Share on other sites

Thanks Sanda.  Appreciate your help.

That gives me a good headstart and I'll take a look at the examples.

Quick question....

Correct me if I'm wrong here....

JasperPrint jasperPrint = JasperFillManager.fillReport(reportFileName, parameters, new WebappDataSource());

In the line above, lets say I've set the parameters object to use a virtualizer and WebappDataSource() class has implemented JRDataSource.
Is it true that fillReport will get all the data from database to fill the JasperPrint Object?  So even though i'm using virtualizer to prevent outofmemory exception and performance problem, it's still going to get ALL the records from the database.  So if I have 1 million recs, it'll get all those records from DB.

Is there a way to prevent this and get ONLY the records specific to the page I'm requesting (assume I'm using JRExporterParameter.PAGE_INDEX)

Thanks
 

Link to comment
Share on other sites

I think this requirement could be satisfied by writing a single page report, using a parametrized query (ie the result set returns only the next 1000 records starting with the <page_number>x1000 +1 -th record; the <page_number> could be set as report parameter each time when a page button is clicked). This single page report has to be rerun each time a next/previous/page_no button is clicked.

If you need to get the entire document (in order to print it, for example) the query could be parametrized with 2 parameters: <start_page_number> and <end_page_number>.

HTH,

sanda



Post Edited by shertage at 09/15/2010 11:05
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...