Pagination in Java
        Posted  
        
            by 
                user569125
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by user569125
        
        
        
        Published on 2011-01-17T23:32:01Z
        Indexed on 
            2011/01/17
            23:53 UTC
        
        
        Read the original article
        Hit count: 139
        
java
|pagination
I wrote paging logic:
My requirement: total elements to display:100 per page,if i click next it should display next 100 records,if i click previous 100 records.
Initial varaible values:
- showFrom:1,
- showTo:100
- max elements:depends on size of data.
- pageSize:100.
Code:
if(p*emphasized text*aging.getAction().equalsIgnoreCase("Next")){
  paging.setTotalRec(availableList.size());
  showFrom = (showTo + 1);
  showTo = showFrom + 100- 1;
  if(showTo >= paging.getTotalRec())
    showTo = paging.getTotalRec();
  paging.setShowFrom(showFrom);
  paging.setShowTo(showTo);
}
else if(paging.getAction().equalsIgnoreCase("Previous")){
  showTo = showFrom - 1;
  showFrom = (showFrom - 100);
  paging.setShowTo(showTo);
  paging.setShowFrom(showFrom);
  paging.setTotalRec(availableList.size());
}
Here i can remove and add the elements to the existing data.above code works fine if i add and remove few elements.but if i remove or add 100 elements at a time counts are not displaying properly above code works fine if i add and remove few elements.
© Stack Overflow or respective owner