title: Maintaining CheckBox status in apex controller
body: <p>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</p>
  
  <pre><code>&lt;apex:pageBlockTable value="{!numbers}" var="n" align="center"&gt;
      &lt;apex:column &gt;
          &lt;apex:inputCheckbox value="{!n.checked}"/&gt;
      &lt;/apex:column&gt; 
      &lt;apex:column value="{!n.cat.Id}" /&gt;
      &lt;apex:column value="{!n.cat.Name}" /&gt;
      &lt;apex:facet name="footer"&gt;Showing Page # {!pageNumber} of {!totalPages}&lt;/apex:facet&gt;
  &lt;/apex:pageBlockTable&gt;
  </code></pre>
  
  <p>I have an OpportunityWrapper class for maintaining checkItem:</p>
  
  <pre><code>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 ;
      }
  }
  </code></pre>
  
  <p>The segment of code for getting list of OpportunityWrapper in custom controller is</p>
  
  <pre><code>public List&lt;OpportunityWrapper&gt; getNumbers() {
      opp = new List&lt;OpportunityWrapper&gt;();
      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;
  }
  </code></pre>
  
  <p>and when the previous button is pressed following method is called</p>
  
  <pre><code>public PageReference Previous() {
      //user clicked previous button
      for ( OpportunityWrapper o : opp ) { 
          if ( o.checked &amp;&amp;  oppId.contains(o.cat.Id) )
              oppId.add(o.cat.Id); 
      }
      selectedPage = '0';
      counter -= list_size;
      return null ;
  }
  </code></pre>
  
  <p>and the following are public member of custom class</p>
  
  <pre><code>private integer counter = 0;  //keeps track of the offset
  private integer list_size = 5;
  public integer total_size; 
  List&lt;OpportunityWrapper&gt; opp ;
  public List&lt;OpportunityWrapper&gt; oppwrapper = new List&lt;OpportunityWrapper&gt;(); //list of Opportunity wrapper shown in the page
  public  Set&lt;String&gt; oppId = new Set&lt;String&gt;(); //set for maintaining which Id's are checked
  </code></pre>
  
  <p>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??</p>