Package org.openfaces.component.table

Examples of org.openfaces.component.table.DataTablePaginator


    @Override
    public void encodeBegin(FacesContext context, UIComponent component) throws IOException {
        super.encodeBegin(context, component);
        if (!component.isRendered())
            return;
        DataTablePaginator paginator = ((DataTablePaginator) component);

        DataTable table = paginator.getTable();

        boolean explicitIdSpecified = false;
        UIComponent immediateFacetChild = null;
        for (UIComponent c = paginator; c != null; c = c.getParent()) {
            if (Rendering.isExplicitIdSpecified(c)) {
                explicitIdSpecified = true;
                break;
            }
            if (c.getParent() == table) {
                immediateFacetChild = c;
                break;
            }
        }
        if (!explicitIdSpecified) {
            if (table.getAbove() == immediateFacetChild || table.getBelow() == immediateFacetChild)
                throw new FacesException("You should explicitly specify id for your <o:dataTablePaginator> or its " +
                        "container which resides in the table's \"above\" or \"below\" facet. See the documentation for " +
                        "details: http://openfaces.org/documentation/developersGuide/datatable.html#DataTable-Specifyingthecontentofthe%22above%22and%22below%22facets");
        }


        ResponseWriter writer = context.getResponseWriter();
        writer.startElement("table", component);
        writer.writeAttribute("border", "0", null);
        writer.writeAttribute("cellspacing", "0", null);
        writer.writeAttribute("cellpadding", "0", null);
        writeIdAttribute(context, component);

        String style = paginator.getStyle();
        String styleClass = paginator.getStyleClass();

        boolean dontShow = (table.getPageCount() < 2 && !paginator.getShowIfOnePage());
        String className = Styles.getCSSClass(context, component, style, DEFAULT_CLASS, styleClass);
        if (dontShow)
            writer.writeAttribute("style", "display: none", null);
        else
            writer.writeAttribute("class", className, null);
View Full Code Here


    @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));
        }
View Full Code Here

    @Override
    public void decode(FacesContext context, UIComponent component) {
        super.decode(context, component);
        Map<String, String> requestParams = context.getExternalContext().getRequestParameterMap();
        DataTablePaginator paginator = (DataTablePaginator) component;
        String clientId = getActionFieldName(context, paginator);
        String actionStr = requestParams.get(clientId);
        DataTable table = paginator.getTable();
        if (actionStr == null || actionStr.length() == 0) {
            String pageIndexId = getPageNoFieldName(context, paginator);
            String newPageIndex = requestParams.get(pageIndexId);
            if (newPageIndex == null) {
                return;
View Full Code Here

TOP

Related Classes of org.openfaces.component.table.DataTablePaginator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.