+ Start a Discussion
abhilash reddy 27abhilash reddy 27 

Pagination with Wrapper Class ( with maintaing the state of selected records)

Hi,
i want maintian the state of selected records while performing pagination i have two apex classe and one controller class.my quetion is if i am saving wrapper class as a apex class it is saving  but while i am saving second apex class which implenting the iterator interface it is giving following error
Error: Compile Error: Type arguments supplied for a non-parameterized type : Iterator at line 1 column 41 
i don't know in which sequence i have to save the three classe can somebody can help on this plzzzz
My three classe are:
1) First class(wrapper class):

global class ContactWrapper {
public Boolean isSelected {get;set;}
public Contact cont{get;set;}            
 public ContactWrapper(Contact cont,Boolean isSelected)     {         
this.cont= cont;        
this.isSelected= isSelected;    
 }     
2)second class(iterator class):
global class  CustomIterable implements Iterator<list<ContactWrapper>> {    
 list<ContactWrapper> InnerList{get; set;}    
list<ContactWrapper> ListRequested{get; set;}    
Integer i {get; set;}    
 public Integer setPageSize {get; set;}    
 public CustomIterable(List<ContactWrapper> lstAccWr)    {        
InnerList = new list<ContactWrapper >();         
ListRequested = new list<ContactWrapper >();           
  InnerList = lstAccWr;       
 setPageSize = 10;       
 i = 0;    
 }       
global boolean hasNext(){        
 if(i >= InnerList.size()) 
{           
 return false;        
 } else {            
return true;         
}    
}         
global boolean hasPrevious(){         
system.debug('I am in hasPrevious' + i);       
 if(i <= setPageSize) {            
return false;         
} else {            
return true;        
 }    
}       
global list<ContactWrapper > next(){               
system.debug('i value is ' + i);      
  ListRequested = new list<ContactWrapper >();         
integer startNumber;       
 integer size = InnerList.size();       
 if(hasNext())        {             
 if(size <= (i + setPageSize))  {                
startNumber = i;               
 i = size;            
}  else  {               
 i = (i + setPageSize);                
startNumber = (i - setPageSize);           
 }                       
 system.debug('i value is =====' + i);           
 system.debug('i value is 2==== ' + (i - setPageSize));                        
for(integer start = startNumber; start < i; start++)    
{               
 ListRequested.add(InnerList[start]);           
 }        
}  
return ListRequested;    
}         
global list<ContactWrapper > previous(){            
  ListRequested = new list<ContactWrapper >();        
 system.debug('i value is previous before =====' + i);       
 integer size = InnerList.size();         
if(i == size)   {            
if(math.mod(size, setPageSize) > 0)            
{                   
 i = size - math.mod(size, setPageSize);          
}  else  {                
i = (size - setPageSize);          
  }         
} else  {          
 i = (i - setPageSize);       
 }               
 system.debug('i value is previous =====' + i);        
system.debug('i value is 2previous ==== ' + (i - setPageSize));                
for(integer start = (i - setPageSize); start < i; ++start)        
{            
ListRequested.add(InnerList[start]);       
}         
return ListRequested;   
 }   
}

3) Controller Class:
public with sharing class CustomPaginationDemo
{
public List<ContactWrapper> lstWrapper {get;set;}
public List<ContactWrapper> lstSetController{get;set;}
CustomIterable obj;    
 public CustomPaginationDemo()      {         
lstWrapper =  new List<ContactWrapper>();        
 lstSetController = new List<ContactWrapper>();         
List<Contact> lstContact = [select id,name from Contact limit 20];                
  for(Contact cont : lstContact )  
{            
 lstWrapper.add(new ContactWrapper(cont ,false));         
}         
obj = new CustomIterable (lstWrapper);          
obj.setPageSize = 5;         
next();              
}                   
public Boolean hasNext {             
get { return obj.hasNext(); }    set;  }                  
public Boolean hasPrevious { get {   return obj.hasPrevious(); }   set;}                 
 public void next()         
 {             
lstSetController = obj.next();        
 }                  
public void previous()          
{             
lstSetController = obj.previous();        
 }     
}
}
4) VF Page:
<apex:page controller="CustomPaginationDemo">
<apex:form >
<apex:pageBlock id="ThePage">
<apex:pageBlockSection columns="1">
<apex:pageBlockTable value="{!lstSetController }" var="obj" >
<apex:column headerValue="Select">
<apex:inputCheckbox value="{!obj.isSelected}"/>
</apex:column>
<apex:column value="{!obj.cont.Name}" headerValue="Name"/>
</apex:pageBlockTable>
<apex:outputPanel >
<apex:commandButton value="<<Previous" action="{!previous}" rendered="{!hasPrevious}" reRender="ThePage" />
<apex:commandButton value="Next >>" action="{!next}" rendered="{!hasNext}" reRender="ThePage" />
</apex:outputPanel>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
karthikeyan perumalkarthikeyan perumal
Hello Abhilash Reddy, 

the above set of code work well. i able to save the  iterator class sucessfully. may be you have some made some chnages. kinldy refere the screens below  vf page out put and iterator class 
User-added image
User-added image
User-added image

if you need i will share those class with vf page.

Thanks
karthik
Amit Chaudhary 8Amit Chaudhary 8
Hi
I hope you are using below post code. For sequence  please check below post
1) http://amitsalesforce.blogspot.com/2014/11/pagination-with-wrapper-class-with.html

I tested full code which is working fine. Please check below link for live demo
1) http://amitblog-developer-edition.ap1.force.com/apex/CustomPaginationDemo

Please try in some other develope org.