Discussions

XML & Web services: How to keep track of how many records to display in a page.

  1. Hi All: I am using Weblogic 9.2, Web Services Client, and Struts. I have a java client in struts that calls a web services. The "ID" field contains a Java integer. The "First_Name" is a Java String. The "Effective_Date" field is a Java date field. The web service returns an arrayList of a class called Result. Code for Result.java: [QUOTE] public class Result { int id; String first_Name; Date effective_Date; public int getId { return id; } public void setId(int id) { this.id=id; } public String getFirst_Name() { return first_Name; } public void setFirst_Name(String first_Name) { this.first_Name = first_Name; } public Date getEffective_Date() { return effective_Date; } public void setEffective_Date(Date effective_Date) { this.effective_Date=effective_Date; } } [/QUOTE] From the arrayList, I displayed the result as the following: ID FIRST_NAME EFFECTIVE_DATE -- --------- ------------- 3 John 9/10/2007 2 Andrew 1/11/2006 5 Peter 3/4/2006 The "ID" header is a link. The "First Name" header is a link. The "EFFECTIVE_Date" is a link. If I clicked on the link "ID", the first time, it will sort the rows in ascending order like the following: ID FIRST_NAME EFFECTIVE_DATE -- --------- ------------- 2 Andrew 1/11/2006 3 John 9/10/2007 5 Peter 3/4/2006 If I clicked on the link "ID", the second time, it will sort the rows in descending order like the following: ID FIRST_NAME EFFECTIVE_DATE -- --------- ------------- 5 Peter 3/4/2006 3 John 9/10/2007 2 Andrew 1/11/2006 If I clicked on the "First_Name" field the first time, it will sort the rows in desceding order. If I clicked on the "First_Name" field the second time, it will sort the rows in ascending order. This applies the same for the "EFFECTIVE_DATE". If the arrayList returns 80 records of class Results.java. I needed to displayed only the first 50 records for the first page and 30 records for the second page. How do I keep track of that so that when I am in the second page, I know to display only record 51 to 80? If I have a arrayList that returns 120 records of class Results.java. In the first page, it displayed only 50 records. In the second page, it displayed only 50 records. In the third page, it displayed only 20 records. Assuming I am able to sort the rows by ID, FirstName and Effective_Date by using Results.java implementing the Java Comparator class. Is it still possible to keep track of how many records displayed in the first page and how many records should be dispalyed in the second page? Any hint would be greatly appreciate. Yours, Frustrated.
  2. Hi, Is the problem simple or am I missing something. If you know the number of records 'n' you want to display in a page, then on any page 'p' you display records from (p-1) * n + 1 So for page no 1, From record = 0 * 50 = 0 To record = From record + n - 1 = 0 + 50 - 1 = 49 So for page no 2, From record = 1 * 50 = 50 To record = From record + n - 2 = 50 + 50 - 1 = 99 for page no 3, From record = 2 * 50 = 100 To record = From record + n - 2 = 100 + 50 - 1 = 149 and so on. Hope this helps. cheers, prakash http://ovisvana.blogspot.com