Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to sort the result return from a web service.

Status
Not open for further replies.

jadeite100

Programmer
May 17, 2006
19
0
0
CA
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.
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".

Any hint would be greatly appreciate.

Yours,

Frustrated.


 
A hint: java.util.Arrays.sort()

How are you displaying the results?

Cheers,
Dian
 
Hi:

I have a web service that returns an arraylist of a class
called Result.
Here is the code for Result.java

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;
}
}

I am displaying result by doing a while loop in the jsp of th arraylist.

 
Look at the java.util.Collections.sort(List, Comparator) method in the Javadocs for your JDK, and also at java.util.Comparator interface. If you implement a Comparator which is capable of comparing two instances of your Result class, then the sort method in Collections can sort an ArrayList (which is a List) using it.

Tim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top