Java
  Home arrow Java arrow Page 4 - Building a Pagination System with AJAX
IBM developerWorks
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Dedicated Servers  
Actuate Whitepapers 
VeriSign Whitepapers 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
IBM developerWorks
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVA

Building a Pagination System with AJAX
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 72
    2006-06-05

    Table of Contents:
  • Building a Pagination System with AJAX
  • Building the dynamic scroll bar
  • Defining the scrolling system’s CSS declarations
  • Defining the (X)HTML markup and JavaScript functions

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Building a Pagination System with AJAX - Defining the (X)HTML markup and JavaScript functions


    (Page 4 of 4 )

    Assuming that you didn't have any problems understanding the CSS rules that I defined before, the (X)HTML markup that makes up the structure of the user interface is simply reduced to the following DIV elements:

    <div id="controlbar" class="handle"></div>

    <div id="scrollbar"></div>

    <div id="datacontainer">Dynamic data goes here</div>

    Did you think the (X)HTML to be defined was much longer? Not at all. As you can see, the three previous DIVS are all the web page elements that I need for creating the structure of the AJAX-based scrolling system. Of course, the first two containers will display the fake scrollbar, while the third one will render the containing structure where the chunks of database records will be appropriately shown.

    Now that you know how the corresponding (X)HTML markup is defined, let me go one step further and show you the skeleton of all the JavaScript functions that will make the scrollbar work as expected, in conjunction with sending the required HTTP requests for fetching database records in the background. Here is how these functions are structured:

    // initialize 'controlbar' element and assign events
    function initControlBar(){
        // function code goes here
    }

    // run code when dragging process starts
    function controlbarOnDragStart(){
        // function code goes here
    }

    // run code during dragging process
    function controlbarOnDrag(){
        // function code goes here
    }

    // run code when dragging process is over
    function controlbarOnDragEnd(){
        // function code goes here
    }

    // get XMLHttpRequest objects
    function getXMLHttpRequestObject(){
        // function code goes here
    }

    // send http requests
    function sendHttpRequest(offset){
        // function code goes here
    }

    // check status of requester objects
    function xmlobjStatusChecker(){
        // function code goes here
    }

    // display database records
    function displayData(){
        // function code goes here
    }

    Okay, I think that’s all with reference to the structural definition of the JavaScript functions, in order to implement the client-side programming of the scrolling application. As you can appreciate, the four first functions are completely aimed at simulating a realistic “drag-and-drop” effect for the handle of the scrollbar, which will be controlled by a JavaScript library that I used in previous DHTML tutorials.

    If this doesn’t sound familiar to you, I’m talking about Michael Foster’s X library, a powerful package that allows you to construct elements that drag easily, among other cool things. Regarding the remaining JavaScript functions, they’re pointed to handling all the HTTP requests via AJAX, as well as displaying the sets of paginated records pulled straight from a database. Simple, right?

    Well, if you want to see the full source code that corresponds to the user interface of the scrolling application, here it is:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
    <head>
      <title>DYNAMIC SCROLLBAR WITH AJAX</title>
     
    <script type="text/javascript">
     
    // initialize 'controlbar' element and assign events
     
    function initControlBar(){
        // function code goes here
     
    }

      // run code when dragging process starts
     
    function controlbarOnDragStart(){
        // function code goes here
     
    }

      // run code during dragging process
     
    function controlbarOnDrag(){
        // function code goes here
     
    }

      // run code when dragging process is over
       
    function controlbarOnDragEnd(){
        // function code goes here
      }

      // get XMLHttpRequest objects
      function getXMLHttpRequestObject(){
        // function code goes here
      }

      // send http requests
      function sendHttpRequest(offset){
        // function code goes here
      }

      // check status of requester objects
      function xmlobjStatusChecker(){
        // function code goes here
      }

      // display database records
      function displayData(){
        // function code goes here
      }

      </script>

      <style type="text/css">

      .handle{

          width: 16px;
          height: 118px;
      
       position: absolute;
     
        background: url('handle1.gif') center center no-repeat;
     
        margin: 0;
       
       padding: 0;
     
        cursor: default;
     
        z-index: 2;
      }

      #scrollbar{

          width: 18px;
     
        height: 500px;
     
        position: absolute;
     
        top: 50px;
     
        left: 700px;
     
        background: url('scrollbar1.gif') center center no-repeat;
      
       margin: 0;
         
    z-index: 1;
     
    }

      #datacontainer{
        width: 500px;
        height: 498px;
        position: absolute;
        top: 50px;
        left: 198px;
        background: #fc6;
        border: 1px solid #ccc;
        margin: 0;
        padding: 5;
     
    }

      p{
        font: normal 12px Verdana, Arial;
        color: #000;
        padding: 5px;
        border: 1px solid #000;
        background: #F7F8CB;
     
    }

      </style>
     
    </head>

     <body>

      <div id="controlbar" class="handle"></div>

      <div id="scrollbar"></div>

      <div id="datacontainer">Dynamic data goes here</div>

     </body>
    </html>

    Wrapping up

    We’re done for now. In this tutorial, I went through the key points for implementing a dynamic scrolling system, which is based on AJAX. As I said before, the main advantage of this mechanism rests on the ease of displaying chunks of database records, without having to include any page links.

    Over the next article, I’ll be writing all the JavaScript code required to put the dynamic scrollbar to work, in addition to performing HTTP requests in the background. Meet you in the next part! 


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · If you're one of those developers wanting to use AJAX in creative ways, then this...
       · One thing that would make this even better is to size the drag handle based upon the...
       · Thank you for commenting on this article. Yeap, definitively, the improvement you...
     

    JAVA ARTICLES

    - Deploying Multiple Java Applets as One
    - Deploying Java Applets
    - Understanding Deployment Frameworks
    - Database Programming in Java Using JDBC
    - Extension Interfaces and SAX
    - Entities, Handlers and SAX
    - Advanced SAX
    - Conversions and Java Print Streams
    - Formatters and Java Print Streams
    - Java Print Streams
    - Wildcards, Arrays, and Generics in Java
    - Wildcards and Generic Methods in Java
    - Finishing the Project: Java Web Development ...
    - Generics and Limitations in Java
    - Getting Started with Java Web Development in...







    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway