title: GWT SimplePager - Add History for every next and previous
body: <p>I need to implement a service like whenever a next or previous is clicked in pagination the browser should save the state so that while doing browser back it goes back to last accessed page.
  Currently it is happening like when I enter any url in new tab page and in pagination if I click on next button, further I click browser back button it is going to new tab page.</p>
  
  <p>Anybody please suggest how to achieve this.</p>
  
  <p>I have tried following</p>
  
  <pre><code>    public class ShortenLastPagePager extends SimplePager implements ValueChangeHandler&lt;String&gt;
  </code></pre>
  
  <p>{</p>
  
  <pre><code>private int pageSize;
  
  
  public ShortenLastPagePager( TextLocation location, Resources resources, boolean showFastForwardButton,
      int fastForwardRows, boolean showLastPageButton, int pageSize )
  {
      super( location, resources, showFastForwardButton, fastForwardRows, showLastPageButton );
      this.pageSize = pageSize;
  }
  
  
  @Override
  public void setPageSize( int pageSize )
  {
      this.pageSize = pageSize;
  }
  
  
  @Override
  public void setPageStart( int index )
  {
      if ( getDisplay() != null ) {
          Range range = getDisplay().getVisibleRange();
          int myPageSize = 0;
  
          index = Math.min( index, getDisplay().getRowCount() );
          index = Math.max( 0, index );
          myPageSize = Math.min( pageSize, getDisplay().getRowCount() - index );
  
          if ( index != range.getStart() || myPageSize != range.getLength() ) {
              getDisplay().setVisibleRange( index, myPageSize );
          }
      }
  }
  
  
  @Override
  public void nextPage()
  {
      if ( getDisplay() != null ) {
          Range range = getDisplay().getVisibleRange();
          setPageStart( range.getStart() + range.getLength() );
      }
  }
  
  
  @Override
  public void previousPage()
  {
      if ( getDisplay() != null ) {
          Range range = getDisplay().getVisibleRange();
          setPageStart( range.getStart() - pageSize );
      }
  }
  
  
  @Override
  public void lastPage()
  {
      int remainder = getDisplay().getRowCount() % pageSize;
      if ( remainder &gt; 0 ) {
          setPageStart( getDisplay().getRowCount() - remainder );
      } else {
          if ( getDisplay().getRowCount() / pageSize &gt; 0 ) {
              setPageStart( getDisplay().getRowCount() - pageSize );
          } else {
              setPageStart( 0 );
          }
      }
  }
  
  
  @Override
  public void firstPage()
  {
      setPageStart( 0 );
  }
  
  
  @Override
  public boolean hasPreviousPage()
  {
      return getDisplay() == null ? false : getDisplay().getVisibleRange().getStart() &gt; 0 &amp;&amp; getDisplay().getRowCount() &gt; 0;
  }
  
  
  @Override
  public boolean hasNextPage()
  {
  
      return getDisplay() == null ? false
          : getDisplay().getRowCount() &gt; ( getDisplay().getVisibleRange().getStart() + pageSize );
  }
  
  
  @Override
  public void onValueChange( ValueChangeEvent&lt;String&gt; event )
  {
      event.getValue();
      System.out.println( event.getSource() );
  }
  </code></pre>
  
  <p>}</p>
  
  <p>It is not hitting onValueChange it is coming to nextPage</p>