⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 scrollercomponent.java

📁 以前做的一个j2ee的项目
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            isPageNumber = true;

            // heuristic: if navActionType is number, and we are not
            // enabled, this must be the current page.
            if (!enabled) {
                facetName = "current";
                isCurrentPage = true;
            }
            break;
        }

        // leverage any navigation facets we have
        writer.write("\n");
//      if (enabled) {
//         writer.write("<a " + getAnchorAttrs(context, clientId,
//                                               navActionType) + ">");
//        }
        if ((navActionType == ACTION_NEXT || navActionType == ACTION_PREVIOUS) &&
            enabled) {
            writer.write("<a " + getAnchorAttrs(context, clientId,
                                                navActionType) + ">");
        } else if (navActionType != ACTION_NEXT &&
                   navActionType != ACTION_PREVIOUS) {
            writer.write("<a " + getAnchorAttrs(context, clientId,
                                                navActionType) + ">");
        }

        facet = getFacet(facetName);
        // render the facet pertaining to this widget type in the NORTH
        // and WEST cases.
        if (facet != null) {
            // If we're rendering a "go to the Nth page" link
            if (isPageNumber) {
                // See if the user specified an orientation
                String facetO = (String) getAttributes().get(
                        FACET_MARKUP_ORIENTATION_ATTR);
                if (facet != null) {
                    facetOrientation = facetO;
                    // verify that the orientation is valid
                    if (!(facetOrientation.equalsIgnoreCase(NORTH) ||
                          facetOrientation.equalsIgnoreCase(SOUTH) ||
                          facetOrientation.equalsIgnoreCase(EAST) ||
                          facetOrientation.equalsIgnoreCase(WEST))) {
                        facetOrientation = NORTH;
                    }
                }
            }

            // output the facet as specified in facetOrientation
            if (facetOrientation.equalsIgnoreCase(NORTH) ||
                facetOrientation.equalsIgnoreCase(EAST)) {
                facet.encodeBegin(context);
                if (facet.getRendersChildren()) {
                    facet.encodeChildren(context);
                }
                facet.encodeEnd(context);
            }
            // The difference between NORTH and EAST is that NORTH
            // requires a <br>.
            if (facetOrientation.equalsIgnoreCase(NORTH)) {
                writer.startElement("br", null); // PENDING(craigmcc)
                writer.endElement("br");
            }
        }

        // if we have a facet, only output the link text if
        // navActionType is number
        if (null != facet) {
            if (navActionType != ACTION_NEXT &&
                navActionType != ACTION_PREVIOUS) {
                if (isCurrentPage) {
                    writer.write("<U><B>" + linkText + "</B></U>");
                } else {
                    writer.write(linkText);
                }
            }
        } else {
            if (isCurrentPage) {
                writer.write("<font color='red'><U>" + linkText + "</U></font>");
            } else {
                if (navActionType == ACTION_NEXT) {
                    String nextImg = getNextImg();
                    writer.write("<img src=" + nextImg +
                                 " border=0 align='absmiddle' title='下一页'/>");
                } else if (navActionType == ACTION_PREVIOUS) {
                    String preImg = getPreImg();
                    writer.write("<img src=" + preImg +
                                 " border=0 align='absmiddle' title='上一页'/>");
                } else if (navActionType != ACTION_NEXT &&
                           navActionType != ACTION_PREVIOUS) {
                    writer.write(linkText);
                }
            }
        }

        // output the facet in the EAST and SOUTH cases
        if (null != facet) {
            if (facetOrientation.equalsIgnoreCase(SOUTH)) {
                writer.startElement("br", null); // PENDING(craigmcc)
                writer.endElement("br");
            }
            // The difference between SOUTH and WEST is that SOUTH
            // requires a <br>.
            if (facetOrientation.equalsIgnoreCase(SOUTH) ||
                facetOrientation.equalsIgnoreCase(WEST)) {
                facet.encodeBegin(context);
                if (facet.getRendersChildren()) {
                    facet.encodeChildren(context);
                }
                facet.encodeEnd(context);
            }
        }

//        if (enabled) {
        writer.write("</a>");
//        }

    }


    /**
     * <p>Build and return the string consisting of the attibutes for a
     * result set navigation link anchor.</p>
     *
     * @param context  the FacesContext
     * @param clientId the clientId of the enclosing UIComponent
     * @param action   the value for the rhs of the =
     *
     * @return a String suitable for setting as the value of a navigation
     *         href.
     */
    private String getAnchorAttrs(FacesContext context, String clientId,
                                  int action) {
        int currentPage = 1;
        //int formNumber = getFormNumber(context);
        String formClientId = getForm(context).getClientId(context);
        Integer curPage = (Integer) getAttributes().get("currentPage");
        StringBuffer sBuffer = new StringBuffer();

        if (curPage != null) {
            currentPage = curPage.intValue();
        }
        sBuffer.append("href=\"javascript: ");
        //sBuffer.append("onclick=\"");
        sBuffer.append("document.forms['" + formClientId + "']['" + clientId);
        sBuffer.append("_action'].value='" + action + "'; ");
        sBuffer.append("document.forms['" + formClientId + "']['" + clientId);
        sBuffer.append("_curPage'].value='" + currentPage + "'; ");

        String paramList = this.getParamList();
        if (paramList != null) {
            String paramValue = null;
            String paramName = null;

            Map requestParameterMap = (Map) context.getExternalContext().
                                      getRequestParameterMap();
            StringTokenizer st = new StringTokenizer(paramList, ";");
            while (st.hasMoreTokens()) {
                paramName = st.nextToken();
                paramValue = (String) requestParameterMap.get(paramName);
                sBuffer.append("document.forms['" + formClientId + "']['");
                sBuffer.append(paramName + "'].value='");
                sBuffer.append(paramValue + "'; ");
            }
        }

        sBuffer.append("document.forms['" + formClientId + "'].submit();\"");
        // sBuffer.append(";return false;");
        return sBuffer.toString();
    }


    private String getHiddenFields(String clientId) {
        StringBuffer sBuffer = new StringBuffer();

        sBuffer.append("<input type=\"hidden\" name=\"" + clientId +
                       "_action\"/>\n");
        sBuffer.append("<input type=\"hidden\" name=\"" + clientId +
                       "_curPage\"/>\n");

        String paramList = this.getParamList();
        if (paramList != null) {
            String paramName = null;
            StringTokenizer st = new StringTokenizer(paramList, ";");
            while (st.hasMoreTokens()) {
                paramName = st.nextToken();
                sBuffer.append("<input type=\"hidden\" name=\"" + paramName +
                               "\"/>\n");
            }
        }

        return sBuffer.toString();
    }


    // PENDING: avoid doing this each time called.  Perhaps
    // store in our own attr?
    protected UIForm getForm(FacesContext context) {
        UIComponent parent = this.getParent();
        while (parent != null) {
            if (parent instanceof UIForm) {
                break;
            }
            parent = parent.getParent();
        }
        return (UIForm) parent;
    }


    protected int getFormNumber(FacesContext context) {
        Map requestMap = context.getExternalContext().getRequestMap();
        int numForms = 0;
        Integer formsInt = null;
        // find out the current number of forms in the page.
        if (null != (formsInt = (Integer)
                     requestMap.get(FORM_NUMBER_ATTR))) {
            numForms = formsInt.intValue();
            // since the form index in the document starts from 0.
            numForms--;
        }
        return numForms;
    }


    /**
     * Returns the total number of pages in the result set based on
     * <code>rows</code> and <code>rowCount</code> of <code>UIData</code>
     * component that this scroller is associated with.
     * For the purposes of this demo, we are assuming the <code>UIData</code> to
     * be child of <code>UIForm</code> component and not nested inside a custom
     * NamingContainer.
     */
    protected int getTotalPages() {
        Integer totalPageCount = (Integer) getAttributes().get("totalPageCount");
        return totalPageCount.intValue();
    }

    protected int getTotalCount() {
        Integer totalCount = (Integer) getAttributes().get("totalCount");
        return totalCount.intValue();
    }

    protected String getPreImg() {
        String preImg = (String) getAttributes().get("preImg");
        return preImg;
    }

    protected String getNextImg() {
        String nextImg = (String) getAttributes().get("nextImg");
        return nextImg;
    }

    protected boolean getIsJump() {
        String isJump = (String) getAttributes().get("isJump");
        if (isJump == null || "".equals(isJump)) {
            isJump = "false";
        }
        return Boolean.valueOf(isJump).booleanValue();
    }

    protected int getCountPage() {
        String countPage = (String) getAttributes().get("countPage");
        if (countPage != null) {
            return Integer.parseInt(countPage);
        } else {
            return 10;
        }
    }


    protected int getRowsPerPage() {
        Integer pageSize = (Integer) getAttributes().get("pageSize");
        return pageSize.intValue();
    }

    protected String getStyle() {
        String style = (String) getAttributes().get("style");
        return style;
    }

    protected String getStyleClass() {
        String styleClass = (String) getAttributes().get("styleClass");
        return styleClass;
    }

    protected String getParamList() {
        String paramList = (String) getAttributes().get("paramList");
        return paramList;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -