// for legacy support, the viewSizeParam is VIEW_SIZE and viewIndexParam is VIEW_INDEX when the fields are "viewSize" and "viewIndex"
if (viewIndexParam.equals("viewIndex" + "_" + paginatorNumber)) viewIndexParam = "VIEW_INDEX" + "_" + paginatorNumber;
if (viewSizeParam.equals("viewSize" + "_" + paginatorNumber)) viewSizeParam = "VIEW_SIZE" + "_" + paginatorNumber;
ServletContext ctx = (ServletContext) request.getAttribute("servletContext");
RequestHandler rh = (RequestHandler) ctx.getAttribute("_REQUEST_HANDLER_");
Map<String, Object> inputFields = UtilGenerics.toMap(context.get("requestParameters"));
// strip out any multi form fields if the form is of type multi
if (modelForm.getType().equals("multi")) {
inputFields = UtilHttp.removeMultiFormParameters(inputFields);
}
String queryString = UtilHttp.urlEncodeArgs(inputFields);
// strip legacy viewIndex/viewSize params from the query string
queryString = UtilHttp.stripViewParamsFromQueryString(queryString, "" + paginatorNumber);
// strip parametrized index/size params from the query string
HashSet<String> paramNames = new HashSet<String>();
paramNames.add(viewIndexParam);
paramNames.add(viewSizeParam);
queryString = UtilHttp.stripNamedParamsFromQueryString(queryString, paramNames);
String anchor = "";
String paginateAnchor = modelForm.getPaginateTargetAnchor();
if (paginateAnchor != null) anchor = "#" + paginateAnchor;
// preparing the link text, so that later in the code we can reuse this and just add the viewIndex
StringBuilder prepLinkTextBuffer = new StringBuilder(targetService);
if (prepLinkTextBuffer.indexOf("?") < 0) {
prepLinkTextBuffer.append("?");
} else if (prepLinkTextBuffer.indexOf("?", prepLinkTextBuffer.length() - 1) > 0) {
prepLinkTextBuffer.append("&");
}
if (!UtilValidate.isEmpty(queryString) && !queryString.equals("null")) {
prepLinkTextBuffer.append(queryString).append("&");
}
prepLinkTextBuffer.append(viewSizeParam).append("=").append(viewSize).append("&").append(viewIndexParam).append("=");
String prepLinkText = prepLinkTextBuffer.toString();
String linkText;
appendWhitespace(writer);
// The current screenlet title bar navigation syling requires rendering
// these links in reverse order
// Last button
writer.append("<li class=\"").append(modelForm.getPaginateLastStyle());
if (highIndex < listSize) {
writer.append("\"><a href=\"");
int lastIndex = UtilMisc.getViewLastIndex(listSize, viewSize);
linkText = prepLinkText + lastIndex + anchor;
// - make the link
writer.append(rh.makeLink(request, response, linkText));
writer.append("\">").append(modelForm.getPaginateLastLabel(context)).append("</a>");
} else {
// disabled button
writer.append(" disabled\">").append(modelForm.getPaginateLastLabel(context));
}
writer.append("</li>");
appendWhitespace(writer);
// Next button
writer.append("<li class=\"").append(modelForm.getPaginateNextStyle());
if (highIndex < listSize) {
writer.append("\"><a href=\"");
linkText = prepLinkText + (viewIndex + 1) + anchor;
// - make the link
writer.append(rh.makeLink(request, response, linkText));
writer.append("\">").append(modelForm.getPaginateNextLabel(context)).append("</a>");
} else {
// disabled button
writer.append(" disabled\">").append(modelForm.getPaginateNextLabel(context));
}
writer.append("</li>");
appendWhitespace(writer);
if (listSize > 0) {
writer.append("<li>");
writer.append(Integer.toString(lowIndex + 1)).append(" - ").append(Integer.toString(lowIndex + actualPageSize)).append(" ").append(ofLabel).append(" ").append(Integer.toString(listSize));
writer.append("</li>");
appendWhitespace(writer);
}
// Previous button
writer.append("<li class=\"nav-previous");
if (viewIndex > 0) {
writer.append("\"><a href=\"");
linkText = prepLinkText + (viewIndex - 1) + anchor;
// - make the link
writer.append(rh.makeLink(request, response, linkText));
writer.append("\">").append(modelForm.getPaginatePreviousLabel(context)).append("</a>");
} else {
// disabled button
writer.append(" disabled\">").append(modelForm.getPaginatePreviousLabel(context));
}
writer.append("</li>");
appendWhitespace(writer);
// First button
writer.append("<li class=\"nav-first");
if (viewIndex > 0) {
writer.append("\"><a href=\"");
linkText = prepLinkText + 0 + anchor;
writer.append(rh.makeLink(request, response, linkText));
writer.append("\">").append(modelForm.getPaginateFirstLabel(context)).append("</a>");
} else {
writer.append(" disabled\">").append(modelForm.getPaginateFirstLabel(context));
}
writer.append("</li>");