Announcement Announcement Module
Collapse
No announcement yet.
PagedListHolder and sorting Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • PagedListHolder and sorting

    I'm looking for an example of how to use the sorting feature of a PagedListHolder

    I'm already using the PagedListHolder to support pagination of table data.

    My JSP is as follows:

    Code:
    <html>
    <head>
    <title>Table</title>
    </head>
    <body>
    
    <c:if test="${reportList!= null}">
    <table >
    	<%@ include file="/WEB-INF/jsp/paging.jsp" %>
    
    	<tr>
    		<th>Person Last Name</th>
    		<th>Person First Name</th>
    		<th>Manager</th>
    	</tr>
    	
    	<%int i=0;%>
    	<c:forEach var="report" items="${reportList.pageList}">
    	  <tr>
    		<td><c:out value="${report.personLastName}"/></td>
    		<td><c:out value="${report.personFirstName}"/></td>
      		<td><c:out value="${report.personManagerEmail}"/></td>
      	  </tr>
    	</c:forEach>
    
    	<%@ include file="/WEB-INF/jsp/paging.jsp" %>
    </table>
    </c:if>
    
    </body>
    </html>
    I'd like to allow the user to be able click on a column header to sort that particular column. I was looking at the PagedListHolder sorting capability for that but am having difficulty understanding its usage. Any examples or documentation will be much appreciated.

    thanks,

  • #2
    No one has used the sorting feature?

    Comment


    • #3
      Hi tsc!

      If you still searching for sorting, maybe I can help you.
      On the JSP page you may use this code:
      Code:
      <c:forEach var="report" items="${reportList.pageList}">
        <tr>
          <td>
            <c:out value="${report.personLastName}"/>
            <a href="?sort=report.personLastName&asc=0"><img src="images/arrow_down.png"/></a>
            <a href="?sort=report.personLastName&asc=1"><img src="images/arrow_up.png"/></a>
          </td>
          <td>
            <c:out value="${report.personFirstName}"/>
            <a href="?sort=report.personFirstName&asc=0"><img src="images/arrow_down.png"/></a>
            <a href="?sort=report.personFirstName&asc=1"><img src="images/arrow_up.png"/></a>
          </td>
          <td>
            <c:out value="${report.personManagerEmail}"/>
            <a href="?sort=report.personManagerEmail&asc=0"><img src="images/arrow_down.png"/></a>
            <a href="?sort=report.personManagerEmail&asc=1"><img src="images/arrow_up.png"/></a>
          </td>
        </tr>
      </c:forEach>
      In the Controller you should implements the following:
      Code:
      public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
        // Make a PagedListHolder list
        PagedListHolder personList = (PagedListHolder) request.getSession().getAttribute("SomethingAttribute");
        // ...
        // Sort
        String sortColumn = request.getParameter("sort");
        if (sortColumn != null)
        {
          try
          {
            personList.setSort(new MutableSortDefinition(sortColumn, true, "1".equals(request.getParameter("asc"))));
            personList.resort();
            // setting the start page info for paging (optional)
            model.put("startPage", 1);
          }
          catch (Exception ex)
          { // ... }
          
          model.put("list", personList);
          request.getSession().setAttribute("SomethingAttribute", personList);
        }
      }
      Good luck!

      Comment


      • #4
        Spring PagedListHolder is very well implemented but i'd suggest you use something like displaytag for a lot more flexibility.

        Comment

        Working...
        X