• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

sorting the result

 
Ranch Hand
Posts: 190
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 751
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 181
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Or if it is in a collection already, use a comparator.

http://java.sun.com/j2se/1.4.2/docs/api/java/util/Comparator.html
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
PradeepPillai Pradeep
Ranch Hand
Posts: 190
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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">
<TBODY>
<tr>
<th> <A href="/sort1.do">Col1</A> </th><th> <A href="/sort2.do">Col2</A> </th> <th> <A href="/sort3.do">Col3</A> </th> <th> <A href="/sort4.do">Col4</A> </th> <th><A href="/sort5.do">Col5</A> </th>
</tr>
<%while(rs.next() ){%>
<TR>
<TD><%=rs.getString(1)%></TD>
<TD><%=rs.getString(2)%></TD>
<TD><%=rs.getString(3)%></TD>
<TD><%=rs.getString(4)%></TD>
<TD><%=rs.getString(5)%></TD>
</TR>
<%}%>
</TBODY>
</TABLE>
-----------------------

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 ]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic