i am writing a visualforce page in which user has to select list of Opportunity i implemented pagination when user click previous button then it will render list panel again and i changed the value of list in the call my visualforce page segment is
<apex:pageBlockTable value="{!numbers}" var="n" align="center">
<apex:column >
<apex:inputCheckbox value="{!n.checked}"/>
</apex:column>
<apex:column value="{!n.cat.Id}" />
<apex:column value="{!n.cat.Name}" />
<apex:facet name="footer">Showing Page # {!pageNumber} of {!totalPages}</apex:facet>
</apex:pageBlockTable>
I have an OpportunityWrapper class for maintaining checkItem:
public class OpportunityWrapper {
public Boolean checked { get; set; }
public Opportunity cat { get; set; }
public OpportunityWrapper(){
cat = new Opportunity();
checked = false;
}
public OpportunityWrapper(Opportunity c){
cat = c;
checked = false;
}
public OpportunityWrapper(Opportunity c, Boolean checked){
cat = c;
this.checked = checked ;
}
}
The segment of code for getting list of OpportunityWrapper in custom controller is
public List<OpportunityWrapper> getNumbers() {
opp = new List<OpportunityWrapper>();
if ( selectedPage != '0' )
counter = list_size*integer.valueOf(selectedPage)-list_size;
//we have to catch query exceptions in case the list is greater than 2000 rows
try {
for ( Opportunity o : [SELECT Id,Name from Opportunity order by name
limit :list_size offset :counter] ) {
if ( !oppId.contains(o.Id) )
opp.add(new OpportunityWrapper(o));
else
opp.add(new OpportunityWrapper(o,true));
}
} catch ( QueryException e ) {
ApexPages.addMessages(e);
return null;
}
return opp;
}
and when the previous button is pressed following method is called
public PageReference Previous() {
//user clicked previous button
for ( OpportunityWrapper o : opp ) {
if ( o.checked && oppId.contains(o.cat.Id) )
oppId.add(o.cat.Id);
}
selectedPage = '0';
counter -= list_size;
return null ;
}
and the following are public member of custom class
private integer counter = 0; //keeps track of the offset
private integer list_size = 5;
public integer total_size;
List<OpportunityWrapper> opp ;
public List<OpportunityWrapper> oppwrapper = new List<OpportunityWrapper>(); //list of Opportunity wrapper shown in the page
public Set<String> oppId = new Set<String>(); //set for maintaining which Id's are checked
My target is when I checked any opportunity wrapper and goto next or previous list and when return back that item should be in checked but i am getting set value always empty but i am storing list of select value in the set of Previous() method why its showing Set always empty??