aspose file tools*
The moose likes Struts and the fly likes sorting problems in struts jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "sorting problems in struts jsp" Watch "sorting problems in struts jsp" New topic
Author

sorting problems in struts jsp

smitha mano
Ranch Hand

Joined: Sep 26, 2005
Posts: 70
I have a page that displays a table with strings coming from collections in multiple columns. When i click on the header, i want the table to be sorted by that column. Can anyone please give me a sample code for the same. This is urgent.

The data table is like: table name is in postgresql : mydata

Company Name Name Email Id Address
--------------------------------------------------------------
TEST COMP Ravi ravi@ravi.com loc1,
COMP ABC Kiran kiran@bl.com loc2,

When i click on the Company Name, i want the table to be sorted by the Company name column.

using with struts jsp .
Scheepers de Bruin
Ranch Hand

Joined: Jul 19, 2005
Posts: 99
Here's one way of doing it:

Create an action that basically loads your resultset, and forwards to the display page. Make the column headings links that link to that action, with parameters in the href attribute like:

href="myaction.do?orderby=firstColumnName"
href="myaction.do?orderby=secondColumnName"
href="myaction.do?orderby=thirdColumnName"

Now in your action class, where you load the resultset by running a query, you just include whatever orderby clause in the actual query.

e.g. "SELECT * FROM tblTest ORDER BY " + request.getParameter("orderby")
This is of course not recommended unless you use prepared statements AND check the values of the "orderby" parameter for validity.

I have not found any other way of sorting a resultset, so if anyone out there knows of a better way - plz share!

[ November 07, 2005: Message edited by: Scheepers de Bruin ]
[ November 10, 2005: Message edited by: Scheepers de Bruin ]

We're doomed!!<br />Yay!!!<br />No that's bad Girr!!<br />Yay!!!
sreenath reddy
Ranch Hand

Joined: Sep 21, 2003
Posts: 415
Hi smitha

You have many third party components which does the things for you . ofcourse you can implement on your own those things which is not really an ardous task . But the third party tools already in place will give you many options for navigating to different set of records and all
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: sorting problems in struts jsp