<html:hidden property="pageNumber" styleId="pageNumber" value="0" />
Propriedade
pageNumber que contém o número da página.
<display:table name="${simpleList}" id="tableList" export="true" pagesize="10" class="simple" requestURIcontext="false" requestURI="?act=searchPaginator" excludedParams="*">
<display:column titleKey="label.personId" sortable="true" headerClass="sortable" style="width: 50%; height: 18">
<html:link href="javascript:doEdit(${count});"><c:out value="${tableList.personId}" /></html:link>
</display:column>
<display:column titleKey="label.name" sortable="true" headerClass="sortable" style="width: 50%; height: 18">
<c:out value="${tableList.name}" />
</display:column>
</display:table>
Propriedade
requestURI contém o método que tratará a paginação.
<script>
/* Altera a chamada dos links do displaytag */
function replaceLinks(tableList) {
if(!isSmartphone()){
if($(tableList)){
var sortLinks = $(tableList).getElementsByTagName('thead')[0]
.getElementsByTagName('a');
ajaxLinks(sortLinks, true);
if (document.getElementsByClassName('pagelinks').length > 0) {
var pagelinks = document.getElementsByClassName('pagelinks')[0]
.getElementsByTagName('a');
ajaxLinks(pagelinks, false);
}
if(document.getElementsByClassName('exportlinks').length > 0){
var links = document.getElementsByClassName('exportlinks')[0]
.getElementsByTagName('a');
exportLinks(links);
}
}
}
}
/* Altera a chamada dos links da exportação dinamicamente */
function exportLinks(links) {
for (i=0; i < links.length; i++) {
links[i].onclick = function() {
var url = this.href;
url += "&pageNumber="+getPageNumber(this.href);
url += "&export=true";
var windowFocus = window.open(url, 'export', '');
windowFocus.focus();
return false;
}
}
}
/* Altera a chamada dos links da paginação dinamicamente */
function ajaxLinks(links, sort) {
for (i=0; i < links.length; i++) {
links[i].onclick = function() {
var url = this.href;
var pars = "pageNumber=";
if(sort){
pars += $("pageNumber").value;
} else {
pars += getPageNumber(this.href);
}
var myAjax = new Ajax.Request(
url,
{
method: 'post',
parameters: pars,
onFailure: showError,
onComplete: showRequest
});
return false;
}
}
}
/* Seta o número da pagina */
function getPageNumber(stringUrl) {
var pageNumber = 1;
if(stringUrl != ""){
var splitUrl = stringUrl.split("=");
pageNumber = (parseInt(splitUrl[splitUrl.length - 1], 10) - 1);
$("pageNumber").value = pageNumber;
}
return pageNumber;
}
replaceLinks("tableList");
</script>
Javascript para alterar os links dinamicamente depois que renderiza na tela.
public ActionForward searchPaginator(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) throws Exception {
try {
String export = request.getParameter("export");
if(export != null && export.equals("true")){
return doExport(actionMapping, actionForm, request, response);
}
SimpleDynaValidatorForm simpleDynaValidatorForm = (SimpleDynaValidatorForm) actionForm;
SimpleBean simpleBean = getBeanView();
BeanUtils.copyProperties(simpleBean, simpleDynaValidatorForm);
SimpleCriteriaExpression expression = new SimpleCriteriaExpression(simpleBean.getClass());
expression.addFilters(SimpleUtil.getMapAttribute(simpleBean), true);
SimplePage page = new SimplePage();
int pageNumber = 0;
String parameterPage = request.getParameter("pageNumber");
try {
if(parameterPage != null && !parameterPage.equals("")){
pageNumber = Integer.parseInt(parameterPage);
} else if(isSmartphone()){
if(request.getQueryString() != null && !request.getQueryString().equals("")){
String[] splitUrl = request.getQueryString().split("=");
pageNumber = (Integer.parseInt(splitUrl[splitUrl.length - 1]) - 1);
}
}
} catch(NumberFormatException nfe) {}
request.setAttribute("pageNumber", new Integer(pageNumber));
page.setPageNumber(pageNumber);
page.setMaxItens((getMaxItens() > 0 ? getMaxItens() : 10));
expression.setPage(page);
List simpleList = new SimplePojoService().get(expression);
if(simpleList != null && !simpleList.isEmpty()){
Long countPage = (Long) request.getSession().getAttribute(COUNT_PAGE);
if(countPage != null && countPage > 0){
List simpleListTotal = new ArrayList(countPage.intValue());
int maxItens = (getMaxItens() > 0 ? getMaxItens() : 10);
for(int i = 0; i < countPage; i++){
if(i == (pageNumber * getMaxItens())){
simpleListTotal.addAll(simpleList);
if(simpleListTotal.size() == countPage){
break;
}
}
if((countPage - maxItens) > i || i < (pageNumber * getMaxItens())){
simpleListTotal.add(null);
} else {
break;
}
}
request.setAttribute("simpleList", simpleListTotal);
} else {
request.setAttribute("simpleList", simpleList);
}
SimpleSort[] simpleSorts = getSimpleSort();
if(simpleSorts != null){
List list = (List) request.getAttribute(SIMPLE_LIST);
if(list != null && !list.isEmpty()){
SimpleUtil.sort(simpleSorts, getBeanView().getClass(), list);
list = null;
}
}
}
} catch(Exception e) {
e.printStackTrace();
throw e;
}
return actionMapping.findForward((isSmartphone() ? FORWARD_HOME : FORWARD_RESULT));
}
Por último o método que controla a paginação, detalhe o tamanho do List sempre é o valor total de registros mas os objetos populados ficam apenas na posição referente ao link da paginação...
Vê se esses pedaços de scripts conseguem te ajudar usei Struts, Hibernate e Ajax(prototype) caso queira posso tentar criar uma versão demo dele...
Sem mais, Rodrigo.