@Override
public void encodeChildren(FacesContext context, UIComponent component) throws IOException {
if (!component.isRendered())
return;
DataTablePaginator paginator = ((DataTablePaginator) component);
DataTable table = paginator.getTable();
int pageCount = table.getPageCount();
if (pageCount < 2 && !paginator.getShowIfOnePage())
return;
int pageSize = table.getPageSize();
if (pageSize == 0)
throw new IllegalStateException("DataTablePaginator can't be placed into a dataTable whose pagination is " +
"not activated. Set dataTable's pageSize to a non-zero value. dataTable's clientId is: " + table.getClientId(context));
boolean firstLinkActive = canSelectFirstPage(table);
boolean lastLinkActive = canSelectLastPage(table);
boolean nextLinkActive = canSelectNextPage(table);
boolean previousLinkActive = canSelectPreviousPage(table);
List<UIComponent> children = component.getChildren();
children.clear();
boolean useAjax = table.getUseAjax();
String actionFieldName = getActionFieldName(context, paginator);
List<String> preloadImages = new ArrayList<String>();
createAndAddActionLink(context, children, paginator, actionFieldName, "selectFirstPage",
getFirstImageUrl(context, paginator, firstLinkActive), getFirstText(paginator),
FIRST_PAGE_COMPONENT, useAjax, table, firstLinkActive);
preloadImages.add(getFirstImageUrl(context, paginator, !firstLinkActive));
boolean showDisabledImages = paginator.getShowDisabledImages();
if ((firstLinkActive && previousLinkActive) || showDisabledImages)
children.add(Components.createOutputText(context, HTML.NBSP_ENTITY, false));
createAndAddActionLink(context, children, paginator, actionFieldName, "selectPrevPage",
getPreviousImageUrl(context, paginator, previousLinkActive), getPreviousText(paginator),
PREV_PAGE_COMPONENT, useAjax, table, previousLinkActive);
preloadImages.add(getPreviousImageUrl(context, paginator, !previousLinkActive));
if (firstLinkActive || previousLinkActive || showDisabledImages)
children.add(Components.createOutputText(context, HTML.NBSP_ENTITY + HTML.NBSP_ENTITY, false));
String pageNumberPrefix = paginator.getPageNumberPrefix();
if (pageNumberPrefix == null)
pageNumberPrefix = DEFAULT_PAGE_NUMBER_PREFIX;
if (pageNumberPrefix.length() > 0)
children.add(Components.createOutputText(context, pageNumberPrefix + HTML.NBSP_ENTITY, false));
HtmlInputText inputText = (HtmlInputText) context.getApplication().createComponent(HtmlInputText.COMPONENT_TYPE);
inputText.setId(Components.generateIdWithSuffix(component, "pageNo"));
String pageNo = String.valueOf(table.getPageIndex() + 1);
inputText.setValue(pageNo);
inputText.setStyle(paginator.getPageNumberFieldStyle());
String fieldClass = Styles.getCSSClass(
context, component, null, DEFAULT_FIELD_CLASS, paginator.getPageNumberFieldClass());
inputText.setStyleClass(fieldClass);
inputText.setOnkeypress("if (event.keyCode == 13) {this.onchange(); O$.stopEvent();}");
Script selectPageNoScript = getSubmitComponentWithParamScript(
useAjax, table, actionFieldName, new RawScript("'selectPageNo:' + this.value"), false);
inputText.setOnchange(selectPageNoScript.toString());
children.add(inputText);
if (paginator.getShowPageCount()) {
String pageCountPreposition = paginator.getPageCountPreposition();
if (pageCountPreposition == null)
pageCountPreposition = DEFAULT_PAGE_COUNT_PREPOSITION;
children.add(Components.createOutputText(context, HTML.NBSP_ENTITY + pageCountPreposition + HTML.NBSP_ENTITY, false));
children.add(Components.createOutputText(context, String.valueOf(pageCount), false));
}