sorting table in a jsp
Hello All,
I want to sort a result set by column name...I'm using MVC pattern ....so I have an if clause to decide the sorting order as:
<c:if test="${sort == asc}">
<a href="Controller?sort=desc" >Student</a>
</c:if>
<c:if test="${sort == desc}">
<a href="Controller?sort=asc" >Student</a>
</c:if>
I'm using a method in my action which sorts the given list ...so my question is how can i save the resultant List to be sorted ...if I put in request ...it can be displayed only one time and can i keep that in session....or is there any other better way to do this....
Thanks,
Maithri
[700 byte] By [
Maithria] at [2007-11-27 4:20:29]

You don't need javascript. Just do it with the javacode in the jsp. You can either: - write a jsp just for sorting, and call that jsp whenever you want to sort from the display jsp.- Write a method in the display jsp to do the sort.
> I need to make less use of session attributes...
If you want to preserve data from one request to another then you need to put it in the user's session. Or alternatively you need to retrieve it again from wherever you retrieved it from the first time. Suit yourself. There are no magic solutions, only ordinary answers.
The JSP generates HTML that is loaded into the browser. Are you asking whether something can be done in that HTML to put information into the next request?
Yes, it can. You could put a copy of the entire table into the next request by making it a whole lot of hidden parameters for the "Controller?sort=asc" URL. But now you are out into the realm of really stupid solutions, so don't do that.
The best solutions are:
1. Sort the data on the client using Javascript.
2. Store the data in the user's session and sort it on the server.
But you have already been told this several times.
Thanks a lot for your replies ...
I'm going with user's session and doing something like this:
HttpSession userSession = request.getSession();
userSession.setAttribute("list",list);......the first time in action
from jsp back to action ...
if(userSession.getAttribute("list") != null ) {
if(sort.equals("asc"))
{
sort(list,asc);
}
Thanks....