This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Struts and the fly likes sorting the result Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "sorting the result" Watch "sorting the result" New topic

sorting the result

PradeepPillai Pradeep
Ranch Hand

Joined: Nov 15, 2005
Posts: 184
I have a result.jsp where I print a resultset in an html table. I want to sort each colum alphabetically. I am implementing this using struts. I want to sort it and print it in the same jsp. Any help appreciated.
Thanks in advance.
Timothy Sam
Ranch Hand

Joined: Sep 18, 2005
Posts: 746
Hi PradeepPillai Pradeep, is that your real name? Anyway, I always tend to sort my records during query like this...

it's much easier this way.

SCJP 1.5 -
Dom Lassy
Ranch Hand

Joined: May 05, 2006
Posts: 181
Or if it is in a collection already, use a comparator.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
For this type of situation, I'd use a JavaScript sort. There are a number of free packages out there that will create a sortable table on your page that can be sorted in ascending or descending order on any column by clickking on the column heading.

I've been using Sortable Table and have been happy with the results.

Consultant, Sima Solutions
PradeepPillai Pradeep
Ranch Hand

Joined: Nov 15, 2005
Posts: 184
What I have now is that I have an html table and a link at the top of each column. When I click the link at the top of each column, it would print the sorted list in another jsp. What I wanted was the sorted result in the same jsp. How can I do this using struts?
I am posting my code here.

ResultSet rs = (ResultSet)request.getAttribute("results");
<TABLE border="1">
<th> <A href="/">Col1</A> </th><th> <A href="/">Col2</A> </th> <th> <A href="/">Col3</A> </th> <th> <A href="/">Col4</A> </th> <th><A href="/">Col5</A> </th>
<%while( ){%>

I don�t have much experience with struts. Please help me if this is not the way to do it.
[ June 02, 2006: Message edited by: PradeepPillai Pradeep ]
It is sorta covered in the JavaRanch Style Guide.
subject: sorting the result
Similar Threads
question on array and printing
How to print contents of JTable !!!Very urgent
Sort and Print HashMap - Please Help
EL expression
using string value as a variable name