Sort a table JSP

I'm populating a table usign SQL and I need to sort a specific column before or during this populating, how can i do this?
[130 byte] By [RIMA33a] at [2007-11-26 14:51:16]
# 1
Why not use the SQL "ORDER BY" to have the database return the result set in the desired order?
tolmanka at 2007-7-8 8:39:26 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
Thanks, the problem here is I'm using a new calculated variable and I'm taking this variable and populated my table.
RIMA33a at 2007-7-8 8:39:26 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

You do mean an HTML table?

Then create a class to represent the data in each row. Populate an ArrayList of these class objects to represent the data in the table. Create a comparator and use this comparator in the Collections.sort method:

http://java.sun.com/j2se/1.4.2/docs/api/java/util/Collections.html#sort(java.util.List,%20java.util.Comparator)

http://java.sun.com/j2se/1.4.2/docs/api/java/util/Comparator.html

tolmanka at 2007-7-8 8:39:26 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

tolmank , has suggested a good solution with JSPs and Java.

Another way to accomplish this is with XML, XSLT and JSTL XML tags.

Populate the data into an XML structure, then transform that XML structure with XSLT and inside the JSP make use of JSTL XML tags to call the transformation.

You can pass the sort-by field as an input parameter to the XSLT via JSTL XML tags used to transform the XML into HTML table.

appy77a at 2007-7-8 8:39:26 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
i've seen free javascript libraries that will allow for sorting on the fly by the user, so clicking on the column header will sort by that column's type, but not sure if that helps much
CarrieHunta at 2007-7-8 8:39:26 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6
You could also use custom tags: http://displaytag.sourceforge.net/11/
tolmanka at 2007-7-8 8:39:26 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...