public void setPaginationComponentHandler(PaginationComponentHandler paginationComponentHandler) {
this.paginationComponentHandler = paginationComponentHandler;
}
public void service(HttpServletRequest request, HttpServletResponse response) throws FormatterException {
PaginationContentProvider contentProvider = getPaginationComponentHandler().getContentProvider();
boolean paginationError = false;
int providerLength = 0;
if ((contentProvider != null)) {
providerLength = getPaginationComponentHandler().getCache().getSize();
if ((providerLength > 0)) {
renderFragment("outputStart");
List elements = null;
try {
getPaginationComponentHandler().calculateValues();
elements = contentProvider.getSublist(getPaginationComponentHandler().getElementToStart(), getPaginationComponentHandler().getElementToEnd());
} catch (Exception e) {
log.warn("Error getting elements to paginate: ", e);
paginationError = true;
MessagesComponentHandler messagesHandler = MessagesComponentHandler.lookup();
messagesHandler.addError("pagination.error");
renderFragment("outputError");
}
if (elements != null && !paginationError) {
if (paginationComponentHandler.isShowHeader())
renderPaginationHeader(contentProvider, providerLength);
if (contentProvider.getPageHeader() != null) includePage(contentProvider.getPageHeader());
for (int i = 0; i < elements.size(); i++) {
if (contentProvider.getPageForElement() != null) {
setAttribute(PARAM_ELEMENT, elements.get(i));
setAttribute(PARAM_INDEX, i);
int position = (getPaginationComponentHandler().getCurrentPage() - 1) * getPaginationComponentHandler().getPageSize() + i;
setAttribute(PARAM_POSITION, position + 1);
setAttribute(PARAM_INVERSE_POSITION, providerLength - position);
includePage(contentProvider.getPageForElement());
if (i < elements.size() - 1 && contentProvider.getPageSeparator() != null)
includePage(contentProvider.getPageSeparator());
}
}
if (contentProvider.getPageBottom() != null) includePage(contentProvider.getPageBottom());
renderPaginationBottom();
}
renderFragment("outputEnd");
}
}
if (!paginationError && contentProvider != null && providerLength == 0 && contentProvider.getPageEmpty() != null)
includePage(contentProvider.getPageEmpty());
}