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

📄 htmldatascrollerrenderer.java

📁 一个使用struts+hibernate+spring开发的完的网站源代码。
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * Copyright 2004 The Apache Software Foundation. *  * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at *  *      http://www.apache.org/licenses/LICENSE-2.0 *  * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package org.apache.myfaces.custom.datascroller;import org.apache.myfaces.renderkit.RendererUtils;import org.apache.myfaces.renderkit.html.HtmlRenderer;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import javax.faces.application.Application;import javax.faces.component.UIComponent;import javax.faces.component.UIData;import javax.faces.component.UIParameter;import javax.faces.component.html.HtmlCommandLink;import javax.faces.component.html.HtmlOutputText;import javax.faces.context.FacesContext;import javax.faces.context.ResponseWriter;import java.io.IOException;import java.util.List;import java.util.Map;/** * @author Thomas Spiegl (latest modification by $Author: svieujot $) * @version $Revision: 1.19 $ $Date: 2005/01/04 01:42:23 $ * $Log: HtmlDataScrollerRenderer.java,v $ * Revision 1.19  2005/01/04 01:42:23  svieujot * Bugfix for last page. * * Revision 1.18  2005/01/04 00:28:07  svieujot * dataScroller, add rowsCountVar, displayedRowsCountVar, firstRowIndexVar and lastRowIndexVar attributes. * * Revision 1.17  2004/12/18 16:31:21  tomsp * fixed issue MYFACES-1 * * Revision 1.16  2004/10/13 11:50:57  matze * renamed packages to org.apache * * Revision 1.15  2004/09/02 08:57:17  manolito * missing setTransient * * Revision 1.14  2004/08/25 16:02:12  manolito * Prevent division by zero in getPageIndex * */public class HtmlDataScrollerRenderer    extends HtmlRenderer{    private static final Log log = LogFactory.getLog(HtmlDataScrollerRenderer.class);    protected static final String FACET_FIRST         = "first".intern();    protected static final String FACET_PREVOIUS      = "previous".intern();    protected static final String FACET_NEXT          = "next".intern();    protected static final String FACET_LAST          = "last".intern();    protected static final String FACET_FAST_FORWARD  = "fastf".intern();    protected static final String FACET_FAST_REWIND   = "fastr".intern();    protected static final String PAGE_NAVIGATION     = "idx".intern();    public static final String RENDERER_TYPE = "org.apache.myfaces.DataScroller";    public boolean getRendersChildren()    {        return true;    }    public void decode(FacesContext context, UIComponent component)    {        RendererUtils.checkParamValidity(context, component, HtmlDataScroller.class);        HtmlDataScroller scroller = (HtmlDataScroller)component;        UIData uiData = findUIData(scroller, component);        if (uiData == null)        {            return;        }        Map parameter = context.getExternalContext().getRequestParameterMap();        String param = (String)parameter.get(component.getClientId(context));        if (param != null)        {            if (param.equals(FACET_FIRST))            {                uiData.setFirst(0);            }            else if (param.equals(FACET_PREVOIUS))            {                int previous = uiData.getFirst() - uiData.getRows();                if (previous >= 0)                    uiData.setFirst(previous);            }            else if (param.equals(FACET_NEXT))            {                int next = uiData.getFirst() + uiData.getRows();                if (next < uiData.getRowCount())                    uiData.setFirst(next);            }            else if (param.equals(FACET_FAST_FORWARD))            {                int fastStep = scroller.getFastStep();                if (fastStep <= 0)                    fastStep = 1;                int next = uiData.getFirst() + uiData.getRows() * fastStep;                int rowcount = uiData.getRowCount();                if (next > rowcount)                     next = (rowcount - 1) - ((rowcount - 1) % uiData.getRows());                uiData.setFirst(next);            }            else if (param.equals(FACET_FAST_REWIND))            {                int fastStep = scroller.getFastStep();                if (fastStep <= 0)                    fastStep = 1;                int previous = uiData.getFirst() - uiData.getRows() * fastStep;                if (previous < 0)                    previous = 0;                uiData.setFirst(previous);            }            else if (param.equals(FACET_LAST))            {                int rowcount = uiData.getRowCount();                int rows = uiData.getRows();                int delta = rowcount % rows;                int first = delta > 0 && delta < rows ? rowcount - delta : rowcount - rows;                if (first >= 0)                {                    uiData.setFirst(first);                }                else                {                    uiData.setFirst(0);                }            }            else if (param.startsWith(PAGE_NAVIGATION))            {                int index = Integer.parseInt(param.substring(PAGE_NAVIGATION.length(), param.length()));                int pageCount = getPageCount(uiData);                if (index > pageCount)                {                    index = pageCount;                }                else if (index <= 0)                {                    index = 1;                }                uiData.setFirst(uiData.getRows() * (index - 1));            }        }    }    public void encodeChildren(FacesContext facescontext, UIComponent uicomponent) throws IOException    {        RendererUtils.checkParamValidity(facescontext, uicomponent, HtmlDataScroller.class);        Map requestMap = facescontext.getExternalContext().getRequestMap();        HtmlDataScroller scroller = (HtmlDataScroller)uicomponent;        UIData uiData = findUIData(scroller, uicomponent);        if (uiData == null)        {            return;        }        String pageCountVar = scroller.getPageCountVar();        if (pageCountVar != null)        {            int pageCount = getPageCount(uiData);            requestMap.put(pageCountVar, new Integer(pageCount));        }        String pageIndexVar = scroller.getPageIndexVar();        if (pageIndexVar != null)        {            int pageIndex = getPageIndex(uiData);            requestMap.put(pageIndexVar, new Integer(pageIndex));        }        String rowsCountVar = scroller.getRowsCountVar();        if (rowsCountVar != null)        {            int rowsCount = uiData.getRowCount();            requestMap.put(rowsCountVar, new Integer(rowsCount));        }        String displayedRowsCountVar = scroller.getDisplayedRowsCountVar();        if (displayedRowsCountVar != null)        {            int displayedRowsCount = uiData.getRows();            int max = uiData.getRowCount()-uiData.getFirst();            if( displayedRowsCount > max )                displayedRowsCount = max;            requestMap.put(displayedRowsCountVar, new Integer(displayedRowsCount));        }        String firstRowIndexVar = scroller.getFirstRowIndexVar();        if (firstRowIndexVar != null)        {            int firstRowIndex = uiData.getFirst()+1;            requestMap.put(firstRowIndexVar, new Integer(firstRowIndex));        }        String lastRowIndexVar = scroller.getLastRowIndexVar();        if (lastRowIndexVar != null)        {            int lastRowIndex = uiData.getFirst()+uiData.getRows();            int count = uiData.getRowCount();            if( lastRowIndex > count )                lastRowIndex = count;            requestMap.put(lastRowIndexVar, new Integer(lastRowIndex));        }        RendererUtils.renderChildren(facescontext, uicomponent);        if (pageCountVar != null)        {            requestMap.remove(pageCountVar);        }        if (pageIndexVar != null)        {            requestMap.remove(pageIndexVar);        }        if (rowsCountVar != null)        {            requestMap.remove(rowsCountVar);        }        if (displayedRowsCountVar != null)        {            requestMap.remove(displayedRowsCountVar);        }        if (firstRowIndexVar != null)        {            requestMap.remove(firstRowIndexVar);        }        if (lastRowIndexVar != null)        {            requestMap.remove(lastRowIndexVar);        }    }    public void encodeEnd(FacesContext facesContext, UIComponent uiComponent) throws IOException    {        RendererUtils.checkParamValidity(facesContext, uiComponent, HtmlDataScroller.class);        ResponseWriter writer = facesContext.getResponseWriter();        HtmlDataScroller scroller = (HtmlDataScroller)uiComponent;        UIData uiData = findUIData(scroller, uiComponent);        if (uiData == null)        {            return;        }        writer.startElement("table", scroller);        String styleClass = scroller.getStyleClass();        if (styleClass != null)        {            writer.writeAttribute("class", styleClass, null);        }        String style = scroller.getStyle();        if (style != null)        {            writer.writeAttribute("style", style, null);        }        writer.startElement("tr", scroller);        UIComponent facetComp = scroller.getFirst();        if (facetComp != null)        {

⌨️ 快捷键说明

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