Hi everybody,
My project calls for development of a table, with different
column such as the following:
NAME SSN SALARY AGE
andrew 111-00-1111 12345 20
tracy 201-01-0101 54545 20
daren 303-33-3333 12135 21
In the table, the SSN is unique for each row, however,
other columns may not be unique. I need to develop a
sorting scheme in the servlet/jsp for the table. For example,
when users click Salary, I need the table to be displayed
from top to bottom with Salary in ascending or descending
order. Of course, it will allow users to sort the table
according to the column they want by clicking any of the
four column titles.
For this project, I don't plan/don't want to write my own
sorting scheme. Instead, I hope to use any existing
Java classes to do the sorting (believing those will be more
efficient anyway). Thus, I don't plan to implement each
column as a single dimension array. Instead, I am thinking
to use Hashmap to store the table. What I am thinking is as
following:
(a) use SSN as the key, since it is unique
(b) for each row, I will have a key (SSN), the
value of the key in the hashmap will be a
string, in
the form of, i.e., 1st row:
"andrew, 12345, 20"
However, by doing so, I encounter some serious problems.
If users click SSN, the table can be sorted, because I
can always sort the key from the hashmap, and then from
the key I get all the corresponding value from the hashmap.
However, when users click other column, such as NAME
or AGE, I have no way to sort the things. Apparently
I am in the wrong path. Do you people have any advice?
Again, I don't want to write my own sorting scheme as long
as I don't have to.
Any kind souls out there please help! Sam