1

¿ How to paginate server side using DisplayTag (and Spring MVC)?

My controller code is like this:

@RequestMapping("/cuenta/refreshCombos.do")
public ModelAndView refreshCombos(HttpServletRequest request, HttpSession session,
        @RequestParam(required= false, value="todas") Boolean todas,
        @RequestParam("idBanco") Long idBanco) throws ParseException{
    Map<String, Object> resul = new HashMap<String, Object>();
    @SuppressWarnings("rawtypes")
    Map paramMap = WebUtils.getParametersStartingWith(request, "d-");

        if (paramMap.size() == 0) {
           if (idBanco == 0){
              cuentaList = obtenerCuentas(0L, true);
           }

           if (idBanco != 0){
              cuentaList = obtenerCuentas(idBanco, false);
           }
        }
    WebUtils.setSessionAttribute(request, "cuentaList", cuentaList);
    resul.put("cuentas", cuentaList);
    return forward("/cuenta/informeCuentas", resul);
}

And my DisplayTag in JSP, like this:

<display:table class="displayTags_wrapper" uid="cuenta" name="sessionScope.cuentaList" pagesize='50' defaultsort="1" defaultorder="ascending" requestURI="">  
    <display:column property="becado" sortable="true" title="Becado" maxLength="25" />  
    <display:column property="apellido" sortable="true" title="Titular Cuenta" maxLength="25" />  
    <display:column property="nroCuil" sortable="true" title="CUIL" maxLength="22" />  
    <display:column property="apellidoRR" sortable="true" headerClass="sortable" title="RR" maxLength="25" />
    <display:setProperty name="basic.empty.showtable" value="true" />  
    <display:setProperty name="paging.banner.group_size" value="35" />  
    <display:setProperty name="paging.banner.item_name" value="cuenta" />  
    <display:setProperty name="paging.banner.item_names" value="cuentas" />  
    <display:setProperty name="paging.banner.onepage" value=" " />
</display:table>

This way, my pager works fine, but client side...

Any help or modifications to server-side paging?

Regards,

CaktusJP.

1 Answer 1

1

See http://www.displaytag.org/1.2/tut_externalSortAndPage.html. The idea is to pass an instance of org.displaytag.pagination.PaginatedList to the tag instead of a java.util.List.

If this is the case, then the tag will generate hrefs with not encoded parameters for the page number to load, the sort criterion and direction (asc, desc) to use, and an optional search ID used, for example, to cache your query result at server-side.

In this case, it's of your responsibility to read these parameters, and perform the queries allowing the creation of a PaginatedList instance.

2
  • Ok, thank you so much!!! But certainly... PaginatedList is an interface and can not be instantiate. You wanted to say I Implement this interface in my DTO or in my Object Entity ? Cheers... CaktusJP. Apr 19, 2011 at 13:47
  • Yes. You should return an instance of this interface from your service layer. Or, if you don't want to depend in displaytag in your service layer, you should return a DTO having the information needed by this interface, and use the Adapter pattern to wrap your DTO inside a PaginatedList interface. See en.wikipedia.org/wiki/Adapter_pattern
    – JB Nizet
    Apr 19, 2011 at 15:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.