aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes AJAX In Practice: implementing pagination? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "AJAX In Practice: implementing pagination?" Watch "AJAX In Practice: implementing pagination?" New topic
Author

AJAX In Practice: implementing pagination?

Preeti Arora
Ranch Hand

Joined: Jan 26, 2007
Posts: 74
Hi,

I want to use AJAX with Java based Applications.I have made search form and implemented pagination on it using JSP.How far this book can help me in using AJAX so that I dont have to refresh entire page when I change search criteria and implement pagination?

Thanks.
[ April 10, 2007: Message edited by: Bear Bibeault ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61429
    
  67

"pp ss",

First thing first. There aren't many rules that you need to worry about here on the Ranch, but one that we take very seriously regards the use of proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Be aware that accounts with invalid display names are not eligible for the book promotion.

Thanks!
bear
JavaRanch Sheriff


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61429
    
  67

OK, with that over I can remove my moderator's hat and put my author hat back on.

Pagination is not a topic that we explicitly touch upon in the book, but the book will most certainly give you the practical experience and know-how to apply Ajax to all sorts of real-world problems; pagination included.

In fact, I very recently implemented a record pagination application using a combination of servlets and JSP with Ajax. The majority of the work was, of course, handled by the database and the Java sever-side code, but Ajax was emplyed so that only the results of the database query could be updated on the page without the need for a full-page refresh.
Preeti Arora
Ranch Hand

Joined: Jan 26, 2007
Posts: 74
Hi,

I have updated my display name.
Sorry about that!

I have already made my application in JSP with page refresh each time with the change in search criteria.I am wondering if adding AJAX will be beneficial in this scenario?

Thanks for the reply.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61429
    
  67

Originally posted by Preeti Srivastava:
I am wondering if adding AJAX will be beneficial in this scenario?


It can be. In the application I mentioned, I only refresh the data grid showing the search results. The rest of the page -- to include the navigation, and the form containing the controls for the search criteria -- do not need to be re-drawn on every search operation.

This not only means that I don't have to do a lot of work to make sure that the form controls are re-initialized with their previous values, it makes things nicer for the user: the results draw faster and there's no page-refresh flicker.
Jord Sonneveld
Author
Ranch Hand

Joined: Apr 09, 2007
Posts: 31
Originally posted by pp ss:
I want to use AJAX with Java based Applications.I have made search form and implemented pagination on it using JSP.How far this book can help me in using AJAX so that I dont have to refresh entire page when I change search criteria and implement pagination?

Like Bear said, we do not cover pagination per-se. However, in the chapter on data caching, we do show how to load data from a server, and show it in the browser in a paginated way. That example will definitely get you started on your way to writing your own pagination.

Prithiraj Sen Gupta
Ranch Hand

Joined: Sep 13, 2006
Posts: 92
Hi,
The subject is very interesting. And challenges the newbies of AJAX to implement this technique.

I would like to know :--

If pagination is done, the server program will call the stored procedure again and again for displaying the data from the database for each page, which will result in automatic page refreshes, and also have to pass through many for's and if's complexity. How AJAX will provide the same data without any page refreshes? How much lesser time will it take than the traditional way. This must be same for sorting and services like searching too.

Thanks and Regards

Prithiraj
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61429
    
  67

Originally posted by Prithiraj Sen Gupta:

If pagination is done, the server program will call the stored procedure again and again for displaying the data from the database for each page


Yes (except that I don't use stored procedures). By fetching the data in small increments -- and by "page" here we mean a "page of data" not an HTML page -- the burden on the database and network is lessened. Users will most commonly find what they are looking for on the first page of data, especially if you provide good searching and filtering tools.

which will result in automatic page refreshes, and also have to pass through many for's and if's complexity


Here I will disagree with you. My implementation of this had very little complexity. You may be over-engineering the process.

How AJAX will provide the same data without any page refreshes?


That's the way Ajax works. Let's say that we have a page with a bunch of navigation and a form that contains the criteria for filtering the records (things like date ranges, or customer numbers, or anything else that makes sense in your business domain). Below the form is an area to show a "page" of results.

When the form is "submitted", the normal form submission process is hijacked (how to do this is explained in great detail in the book) and the request is channeled to an Ajax request.

When the request returns its repsonse - in my case a fully formatted HTML table containing the "page" of results -- it is inserted into the area reserved for the results.

Since the page never reloaded, the navigation and the form never changed or needed to be repainted. The amount of data coming back as the response was limited to only the data grid showing the current "page" of data.

How much lesser time will it take than the traditional way.


Whatever time is saved not having to send the markup for, and re-render, the unchanged parts of the page.

That help?
Preeti Arora
Ranch Hand

Joined: Jan 26, 2007
Posts: 74
Hi,

I m trying to implement pagination using AJAX but facing lot of challenges.
I also want the sorting of results by clicking on table headers.
Its getting more complex for me!

Thanks.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61429
    
  67

It needn't be. Here's a few concepts regarding sorting from my implementation.

Hidden inputs in the form used to submit the search criteria contains the following information:

- current page number (results "page" not HTML page)
- pages size (in other words, number of records to be shown)
- sort column
- sort direction

These values are submitted with the rest of the filter criteria and are used to format the JDBC query to be executed.

When a column header is clicked, I use an onclick handler to set the new column name as the sort column value and submit the form (though Ajax of course). The JDBC query is created with an "order by" clause using that column. Easy as pie!

If the clicked column happens to be the current column, I flip the sort direction value so users can sort in either ascending or descending order.
[ April 11, 2007: Message edited by: Bear Bibeault ]
Preeti Arora
Ranch Hand

Joined: Jan 26, 2007
Posts: 74
Thanks, this surely will help!
Prithiraj Sen Gupta
Ranch Hand

Joined: Sep 13, 2006
Posts: 92
Yes Bear, It helped. Thanks for explaining.

That is the nicest statement (Very simple and straight ):

Whatever time is saved not having to send the markup for, and re-render, the unchanged parts of the page.


Thanks & Regards

Prithiraj
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61429
    
  67

Glad to be of help! This is perhaps a subject that I should consider for a JavaRanch Journal article in the future.
Prithiraj Sen Gupta
Ranch Hand

Joined: Sep 13, 2006
Posts: 92
Originally posted by Bear Bibeault:


Yes (except that I don't use stored procedures).


I couldnt understand this. How without using stored procedures you fetch data from database...?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61429
    
  67

Originally posted by Prithiraj Sen Gupta:
I couldnt understand this. How without using stored procedures you fetch data from database...?


JDBC
Prithiraj Sen Gupta
Ranch Hand

Joined: Sep 13, 2006
Posts: 92
Hello Bear,


JDBC is a bridge between database and Java programming. Any way you have to write PL/SQL to retrieve data. Even JDBC is used to call these stored Procedure. So How Could you Retrieve data without using Stored Procedure? Since the Question is not related to this forum you can send me a private message..

Thanks & Regards

Prithiraj Sen Gupta
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61429
    
  67

Stored procedures are not required to use JDBC. Just becasue you can cause stored procedures to be triggered via JDBC doesn't mean that that's the only way to use it. I think you may need to read up on this subject or post questions in the JDBC forum.

Answering questions via PM is discouraged.
[ April 27, 2007: Message edited by: Bear Bibeault ]
 
 
subject: AJAX In Practice: implementing pagination?