Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6717971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:54:54+00:00 2026-05-26T08:54:54+00:00

Can anyone provide some idea/logic to write the pagination logic for the search page

  • 0

Can anyone provide some idea/logic to write the pagination logic for the search page i am working on?
The information i have is total number of pages for that search- 10 records per page also i am been sent the both the previous and next page number(no problem writing the logic all i need to do i pull that info and populate. I am also getting the info which page i am on. I can only display 10 pages like below

<previous 1 |2 |3 | 4| 5 | 6 | 7 | 8 | 9 | 10 next>

Say if total pages are 15 and when user click next then i need to display like this

<previous 2 |3 |4 |5 |6 |7 |8 |9 |10 |11 next>

At any time i just need to show then 10 pages in the pagination.

 #set($start = 1)
 #set($end = $Integer.parseInt($searchTO.getPagination().getNumberofPages()))
 #set($range = [$start..$end])

#set($iter = 1)
            #foreach($i in $range)
              #foreach($link in $searchTO.getPagination().getDirectPageLinks())
                    #if($i == $iter)
                        #if ($Integer.parseInt($searchTO.getPagination().getPageNumber())==$iter)
                            <a class="search_current" href="/?_page=SEARCH&_action=SEARCH$link">$i &nbsp|</a>
                        #else
                            <a href="/?_page=SEARCH&_action=SEARCH$link">$i &nbsp|</a>
                        #end
                        #set($iter = 1)
                        #break
                    #else
                        #set($iter=$iter+1)
                    #end

                 #end

            #end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T08:54:54+00:00Added an answer on May 26, 2026 at 8:54 am

    Here is how I would implement it:
    It is generally a good idea to create a Filter class that filters data and contains pagination related information for you. I use something like this:

    public abstract class Filter{
    
         /** Member identifier for the current page number */
         private int currentPageNo;
    
         /** Member identifier for the current start page number in the page navigation */
         private int currentStartPageNo;
    
         /** Member identifier for the current end page number in the page navigation */
         private int currentEndPageNo;
    
         /** Member identifier for the number of elements on a page */
         private int elementsPerPage;
    
         /** Member identifier for the number of pages you have in the navigation (i.e 2 to  11 or 3 to 12 etc.) */      
         private int pageNumberInNavigation;
    
         public abstract Query createCountQuery();
    
         public abstract Query createQuery();
    
         public void setCurrentPageNo(){
             //Your code here
             //Validation, variable setup
         }
    
         public Long getAllElementsCount(){
              //Now this depends on the presistence framework you use, this code is
              //just for guidance and has Hibernate-like syntax
              Query query = createCountQuery();
              List list = query.list();
              return !list.isEmpty() && list.get(0) != null ? query.list().get(0) : 0;
         }
    
         public List getElements(){
              //Now this depends on the presistence framework you use, this code is
              //just for guidance and has Hibernate-like syntax
             Query query = createQuery();
             int from = ((currentPageNo - 1) * elementsPerPage);
             query.setFirstResult(from);
             query.setMaxResults(elementsPerPage);
             //If you use Hibernate, you don't need to worry for null check since if there are no results then an empty collection is returned
             return query.list();
         }
    
         public List getAllElements(){
             Query query = createQuery();
             return query.list();
         }
    
         public void refresh(){
             //Your code here
         }
    
         public List next(){
             //Move to the next page if exists
             setCurrentPageNo(getCurrentPageNo() + 1);
             getElements();
         }
    
         public List previoius(){
             //Move to the previous page if exists
             setCurrentPageNo(getCurrentPageNo() - 1);
             getElements();
         }
    
    }
    

    You could have special subclasses of filters (depending on what you want to retrieve) and and each subclass would implement it’s createCountQuery() and createQuery().

    You would put then your Filter to the Velocity context and you could retrieve all the information you need from this class.

    When you set the current page pf course you update all the other information that you need (i.e. currentStartPageNo, currentEndPageNo).

    You could also have a refresh() method to put the filter back to its initial state.

    And of course you should keep the instance of the same filter on the session (I mean you web framework like Struts, Turbine etc.) while the user navigates on the search page to which the Filter belongs.

    This is just a guideline, an idea, it is not fully written executable code, just an example to get you started in a direction.

    I would also recommend you a jQuery plugin called jqGrid that has pagination support (although you have to have a backed to retrieve data) and a lot more cool stuff.
    You can use it to display your data in a grid. I use it together with Velocity with no problem. It has a lot of very nice and useful features like filter toolbar, editable cells, data transfer in JSON, XML etc.
    Honestly, I do not know if it has pagination like you need (I use it with only one page displayed in the navigation and you can not click on a page just use the next a prev buttons to navigate), but it may have support for that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anyone provide some links to good information on setting up Silverlight 2.0 to
Can anyone provide some information on how to run an integration services package, on
I need to implement the gauge in iOS: Can anyone provide me some idea
Can anyone please provide me some idea/guidance on how to save an image from
Can anyone provide a regex for notepad++ for the below search and replace (conversion)
How can I write some information inside a photo file like jpg or gif
Can anyone provide me with a hello world example for a major mode in
Can anyone provide me an example of how to use WM_CLOSE to close a
Can anyone provide details on what the three of these mean? System::ContainerStartTime System::CreationDate System::StartTime
Can anyone provide a function to sanitize input for a UniData query? Or provide

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.