Pagination funtionality for only limited records to be displayed in the table
private ArrayList<Integer> pagination = new ArrayList<Integer>(); private ArrayList<Integer> temppagination = new ArrayList<Integer>(); int resultprofilelen = resultProfiles.size(); if(resultprofilelen != 0 && resultprofilelen <=20) { showpage = false; showmessage = "Showing all of "+resultprofilelen+" Results"; tempresultprofiles =resultProfiles; tempresultprofiles = profileService.getimageid(tempresultprofiles); } if(resultprofilelen >20) { int reminder=resultprofilelen%20; int numberpages = resultprofilelen/20; showpage = true; for(int i=1; i<=numberpages;i++) { pagination.add(i); } if(reminder>=1) { pagination.add(pagination.size()+1); } if(pagination.size()>10) { currentpage = 1; page(); } else temppagination= pagination; currentpage = 1; previousflag = false; nextflag = true; showmessage = "Showing "+ currentpage*1+" - "+currentpage*20 +" of "+resultprofilelen; tempresultprofiles = resultProfiles.subList(0, 20); tempresultprofiles = profileService.getimageid(tempresultprofiles); } public String page() { String forward; int startindex =0; int endindex =20; int nopages=pagination.size(); startindex = (currentpage-1)*20+1; if(currentpage == nopages) endindex =resultProfiles.size(); if(currentpage < nopages) endindex =currentpage*20; if(currentpage == nopages) tempresultprofiles = resultProfiles.subList(startindex-1,resultProfiles.size()); else tempresultprofiles = resultProfiles.subList(startindex-1,endindex); forward = forwardSearchResultPage; showmessage = "Showing "+ startindex+" - "+endindex +" of "+resultProfiles.size(); if(currentpage ==1) { previousflag= false; nextflag= true; } if(currentpage >1 && currentpage != nopages) { previousflag= true; nextflag= true; } if(currentpage== nopages) { previousflag= true; nextflag= false; } temppage(); tempresultprofiles= profileService.getimageid(tempresultprofiles); return forward; } public void first() { currentpage = 1; page(); } public void previous() { currentpage = currentpage-1; page(); } public void next() { currentpage = currentpage+1; page(); } public void last() { currentpage = pagination.size(); page(); } public void temppage() { temppagination = new ArrayList<Integer>(); int startindex =0; int endindex=0; if(pagination.size()>10) { if(currentpage >5) { int diff = pagination.size()-currentpage; if(diff >=5) startindex = currentpage- 4; else startindex = pagination.size() - 10; } else startindex = 0; if(pagination.size()>=startindex+9) { endindex = startindex+10; } else endindex=pagination.size(); for(int i= startindex; i<endindex;i++) { temppagination .add(i+1); } } else temppagination = pagination; }