Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

sorting problems in struts jsp

 
smitha mano
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
sreenath reddy
Ranch Hand
Posts: 415
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic