I have an ArrayList
of Book
s pulled from different Merchant
s and sorted in Java, depending on user preferences, according to price or customer reviews:
List<Book> books = new ArrayList<Book>();
This requires me to keep a large chunk of data in memory stored as Java objects at all times. Now that I need to paginate this data into listings that span multiple web pages and allow a user to click on a numbered page link to hop to that segment of the data, what's the best way to do this?
My idea was to have maybe 25 book listings per page and rather than use hyperlinks that submit the form data as a GET
request of URL parameters, the page number hyperlinks would simply resubmit the form, passing the requested page number as an additional form POST
parameter.
<input type="hidden" id="pageNumber" value="0">
<a href="#" onClick="pageNumber=5; this.form.submit()">Page 5</a>
In that case page 5 would simply be a set of 25 records starting at the 125th (5 * 25) record in the ArrayList
and ending at the 149th record in the ArrayList
.
Is there a better way to do this?