Link to home
Start Free TrialLog in
Avatar of komlaaa
komlaaa

asked on

sorting by clicking a link

Hi Experts,
I have a jsp page(the view) as shown below. It displays beans that are coming from a servlet.
I would like have the header of my table used to display the bean as link so that when clicked, it sorts the beans by that field. I know how to implement the method that sorts a list of bean(as shown below ).

My question: How can i setup that link so that when clicked the jsp view is reloaded and the tabel is sorted by the field clicked?
 
==================== Sorter implementation =============
class CountryComparator implements Comparator { public int compare(Object
        obj1, Object obj2) { IpInfoBean bean1 = (IpInfoBean) obj1; IpInfoBean
        bean2 = (IpInfoBean) obj2; return ( bean1.getCountry().trim()
        ).compareToIgnoreCase( bean2.getCountry().trim() ); }
         }

and called as: Collections.sort( listOfBean, new CountryComparator() );
================= the jsp view ===================
<jsp:useBean id="listOfipInfo" type="java.util.ArrayList<IpInfoBean>" scope="request"/>
 
<center>
<b>Total # of IP: <%= request.getAttribute("numOfCountry")%></b><br>
<table border="1">
<tr>
      <th>IP</th>
      <th>Country</th>
      <th># of Country/IP</th>
</tr>
<% for(IpInfoBean b : listOfipInfo ) { %>
<tr>
      <td><%= b.getIps() %></td>
      <td><%= b.getCountry() %></td>
      <td><%= b.getCountryCount() %></td>
ASKER CERTIFIED SOLUTION
Avatar of fargo
fargo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial