{
setFirst(0);
return;
}
CollectionModel model = getCollectionModel();
int oldIndex = model.getRowIndex();
try
{
model.setRowIndex(first);
// if the starting row doesn't exist then we need to scroll back:
if (!model.isRowAvailable())
{
int size = model.getRowCount();
int rows = getRows();
// if the rowCount is unknown OR
// the blockSize is show all OR
// there are fewer rows than the blockSize on the table
// then start from the beginning:
if ((size <= 0) || (rows <= 0) || (size <= rows))
first = 0;
else
{
// scroll to the last page:
first = size - rows;
model.setRowIndex(first);
// make sure the row is indeed available:
if (!model.isRowAvailable())
{
// row is not available. this happens when getRowCount() lies.
// Some DataModel implementations seem to have rowCount methods which
// lie. see bug 4157186
first = 0;
}
}
setFirst(first);
}
}
finally
{
model.setRowIndex(oldIndex);
}
}