this.requestAttributes = requestAttributes;
}
public int doEndTag() throws JspException {
StringBuffer results = new StringBuffer();
Pager pager = (Pager) TagUtils.getInstance().lookup(pageContext, pagerName, pagerProperty, null);
if (pager != null && pager.getModel().getRowCount() >= Integer.parseInt(PageSizeTag.PAGE_SIZES[0])) {
// String imagePath =
// CoreUtil.getThemePath(pageContext.getSession()) +
// "/images/actions/";
// Start of table
results.append("<ul><li>");
results.append("<a href=\"");
if (pager.getStartRow() > 0) {
results.append(getPageLink(0, pager));
} else {
results.append("javascript: void();");
}
results.append("\"");
results.append(makeStyles(false, false));
results.append(">");
results.append("<div class=\"firstPage\"><span><<</span></div>");
results.append("</a></li>");
// Previous page
results.append("<li><a href=\"");
if (pager.getHasPreviousPage()) {
results.append(getPageLink(pager.getStartRow() - pager.calcPageSize(), pager));
} else {
results.append("javascript: void();");
}
results.append("\"");
results.append(makeStyles(false, false));
results.append(">");
results.append("<div class=\"previousPage\"><span><</span></div>");
results.append("</a></li>");
// Pages
int currPage = pager.getPageSize() == 0 ? 0 : (pager.getStartRow() / pager.getPageSize()) + 1;
int maxToDisplay = 10;
int page = Math.max(1, currPage - (maxToDisplay / 2));
int idx = (page - 1) * pager.getPageSize();
for (int pageIdx = 0; pageIdx < maxToDisplay && idx < pager.getFilteredRowCount(); pageIdx++) {
boolean selected = idx >= pager.getStartRow() && idx < pager.getStartRow() + pager.calcPageSize();
results.append("<li><a href=\"");
results.append(selected ? "#" : getPageLink(idx, pager));
results.append("\" ");
results.append(makeStyles(false, selected));
results.append("><div class=\"pageNumber\">");
results.append(page);
results.append("</div></a></li>");
page++;
idx += pager.calcPageSize();
}
// Next page
results.append("<li><a href=\"");
if (pager.getHasNextPage()) {
results.append(getPageLink(pager.getStartRow() + pager.getPageSize(), pager));
} else {
results.append("javascript: void();");
}
results.append("\"");
results.append(makeStyles(false, false));
results.append(">");
results.append("<div class=\"nextPage\"><span>></span></div>");
results.append("</a></li>");
// Last page
results.append("<li><a href=\"");
if (pager.getPageSize() != 0) {
int leftOverRows = pager.getFilteredRowCount() % pager.getPageSize();
int lastPageRow = pager.getFilteredRowCount() - leftOverRows;
if (pager.getStartRow() < lastPageRow && lastPageRow < pager.getFilteredRowCount()) {
results.append(getPageLink(lastPageRow, pager));
} else if (leftOverRows == 0) {
results.append(getPageLink(lastPageRow - pager.getPageSize(), pager));
} else {
results.append("javascript: void();");
}
} else {
results.append("javascript: void();");