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

📄 tabletag.java

📁 dispalytag的源码
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
    private String getConfiguredDecoratorName()    {        String tableDecoratorName = (this.decoratorName == null) ? this.properties            .getMediaTypeDecoratorName(this.currentMediaType) : this.decoratorName;        tableDecoratorName = (tableDecoratorName == null) ? this.properties            .getExportDecoratorName(this.currentMediaType) : tableDecoratorName;        return tableDecoratorName;    }    /**     * clean up instance variables, but not the ones representing tag attributes.     */    private void cleanUp()    {        // reset instance variables (non attributes)        this.currentMediaType = null;        this.baseHref = null;        this.caption = null;        this.captionTag = null;        this.currentRow = null;        this.doAfterBodyExecuted = false;        this.footer = null;        this.listHelper = null;        this.pageNumber = 0;        this.paramEncoder = null;        this.properties = null;        this.rowNumber = 1;        this.tableIterator = null;        this.tableModel = null;        this.list = null;        this.paginatedList = null;    }    /**     * If no columns are provided, automatically add them from bean properties. Get the first object in the list and get     * all the properties (except the "class" property which is automatically skipped). Of course this isn't possible     * for empty lists.     */    private void describeEmptyTable()    {        this.tableIterator = IteratorUtils.getIterator(this.list);        if (this.tableIterator.hasNext())        {            Object iteratedObject = this.tableIterator.next();            Map objectProperties = new HashMap();            // if it's a String don't add the "Bytes" column            if (iteratedObject instanceof String)            {                return;            }            // if it's a map already use key names for column headers            if (iteratedObject instanceof Map)            {                objectProperties = (Map) iteratedObject;            }            else            {                try                {                    objectProperties = BeanUtils.describe(iteratedObject);                }                catch (Exception e)                {                    log.warn("Unable to automatically add columns: " + e.getMessage(), e);                }            }            // iterator on properties names            Iterator propertiesIterator = objectProperties.keySet().iterator();            while (propertiesIterator.hasNext())            {                // get the property name                String propertyName = (String) propertiesIterator.next();                // dont't want to add the standard "class" property                if (!"class".equals(propertyName)) //$NON-NLS-1$                {                    // creates a new header and add to the table model                    HeaderCell headerCell = new HeaderCell();                    headerCell.setBeanPropertyName(propertyName);                    // handle title i18n                    headerCell.setTitle(this.properties.geResourceProvider().getResource(                        null,                        propertyName,                        this,                        this.pageContext));                    this.tableModel.addColumnHeader(headerCell);                }            }        }    }    /**     * Called when data are not displayed in a html page but should be exported.     * @return int SKIP_PAGE     * @throws JspException generic exception     */    protected int doExport() throws JspException    {        boolean exportFullList = this.properties.getExportFullList();        if (log.isDebugEnabled())        {            log.debug("[" + getUid() + "] currentMediaType=" + this.currentMediaType);        }        boolean exportHeader = this.properties.getExportHeader(this.currentMediaType);        boolean exportDecorated = this.properties.getExportDecorated();        ExportView exportView = ExportViewFactory.getInstance().getView(            this.currentMediaType,            this.tableModel,            exportFullList,            exportHeader,            exportDecorated);        try        {            writeExport(exportView);        }        catch (IOException e)        {            throw new WrappedRuntimeException(getClass(), e);        }        return SKIP_PAGE;    }    /**     * Will write the export. The default behavior is to write directly to the response. If the ResponseOverrideFilter     * is configured for this request, will instead write the exported content to a map in the Request object.     * @param exportView export view     * @throws JspException for problem in clearing the response or for invalid export views     * @throws IOException exception thrown when writing content to the response     */    protected void writeExport(ExportView exportView) throws IOException, JspException    {        String filename = properties.getExportFileName(this.currentMediaType);        HttpServletResponse response = (HttpServletResponse) this.pageContext.getResponse();        HttpServletRequest request = (HttpServletRequest) this.pageContext.getRequest();        Map bean = (Map) request.getAttribute(FILTER_CONTENT_OVERRIDE_BODY);        boolean usingFilter = bean != null;        String mimeType = exportView.getMimeType();        // original encoding, be sure to add it back after reset()        String characterEncoding = response.getCharacterEncoding();        if (usingFilter)        {            if (!bean.containsKey(TableTagParameters.BEAN_BUFFER))            {                // We are running under the export filter, call it                log.debug("Exportfilter enabled in unbuffered mode, setting headers");                response.addHeader(TableTagParameters.PARAMETER_EXPORTING, TagConstants.EMPTY_STRING);            }            else            {                // We are running under the export filter in buffered mode                bean.put(TableTagParameters.BEAN_CONTENTTYPE, mimeType);                bean.put(TableTagParameters.BEAN_FILENAME, filename);                if (exportView instanceof TextExportView)                {                    StringWriter writer = new StringWriter();                    ((TextExportView) exportView).doExport(writer);                    bean.put(TableTagParameters.BEAN_BODY, writer.toString());                }                else if (exportView instanceof BinaryExportView)                {                    ByteArrayOutputStream stream = new ByteArrayOutputStream();                    ((BinaryExportView) exportView).doExport(stream);                    bean.put(TableTagParameters.BEAN_BODY, stream.toByteArray());                }                else                {                    throw new JspTagException("Export view "                        + exportView.getClass().getName()                        + " must implement TextExportView or BinaryExportView");                }                return;            }        }        else        {            log.debug("Exportfilter NOT enabled");            // response can't be already committed at this time            if (response.isCommitted())            {                throw new ExportException(getClass());            }            try            {                response.reset();                pageContext.getOut().clearBuffer();            }            catch (Exception e)            {                throw new ExportException(getClass());            }        }        if (!usingFilter && characterEncoding != null && mimeType.indexOf("charset") == -1) //$NON-NLS-1$        {            mimeType += "; charset=" + characterEncoding; //$NON-NLS-1$        }        response.setContentType(mimeType);        if (StringUtils.isNotEmpty(filename))        {            response.setHeader("Content-Disposition", //$NON-NLS-1$                "attachment; filename=\"" + filename + "\""); //$NON-NLS-1$ //$NON-NLS-2$        }        if (exportView instanceof TextExportView)        {            Writer writer;            if (usingFilter)            {                writer = response.getWriter();            }            else            {                writer = pageContext.getOut();            }            ((TextExportView) exportView).doExport(writer);        }        else if (exportView instanceof BinaryExportView)        {            // dealing with binary content            // note that this is not assured to work on any application server if the filter is not enabled. According            // to the jsp specs response.getOutputStream() should no be called in jsps.            ((BinaryExportView) exportView).doExport(response.getOutputStream());        }        else        {            throw new JspTagException("Export view "                + exportView.getClass().getName()                + " must implement TextExportView or BinaryExportView");        }        log.debug("Export completed");    }    /**     * This sets the list of all of the data that will be displayed on the page via the table tag. This might include     * just a subset of the total data in the list due to to paging being active, or the user asking us to just show a     * subset, etc...     */    protected void setupViewableData()    {        // If the user has changed the way our default behavior works, then we need to look for it now, and resort        // things if needed before we ask for the viewable part. (this is a bad place for this, this should be        // refactored and moved somewhere else).        if (this.paginatedList == null || this.tableModel.isLocalSort())        {            if (this.tableModel.isSortFullTable())            {                // Sort the total list...                this.tableModel.sortFullList();            }        }        Object originalData = this.tableModel.getRowListFull();        // If they have asked for a subset of the list via the length        // attribute, then only fetch those items out of the master list.        List fullList = CollectionUtil.getListFromObject(originalData, this.offset, this.length);        int pageOffset = this.offset;        // If they have asked for just a page of the data, then use the        // SmartListHelper to figure out what page they are after, etc...        if (this.paginatedList == null && this.pagesize > 0)        {            this.listHelper = new SmartListHelper(fullList, (this.partialList) ? ((Integer) size).intValue() : fullList                .size(), this.pagesize, this.properties, this.partialList);            this.listHelper.setCurrentPage(this.pageNumber);            pageOffset = this.listHelper.getFirstIndexForCurrentPage();            fullList = this.listHelper.getListForCurrentPage();        }        else if (this.paginatedList != null)        {            this.listHelper = new PaginatedListSmartListHelper(this.paginatedList, this.properties);        }        this.tableModel.setRowListPage(fullList);        this.tableModel.setPageOffset(pageOffset);    }    /**     * Uses HtmlTableWriter to write table called when data have to be displayed in a html page.     * @throws JspException generic exception     */    protected void writeHTMLData() throws JspException    {        JspWriter out = this.pageContext.getOut();        String css = this.properties.getCssTable();        if (StringUtils.isNotBlank(css))        {            this.addClass(css);        }        // use HtmlTableWriter to write table        new HtmlTableWriter(            this.tableModel,            this.properties,            this.baseHref,            this.export,            out,            getCaptionTag(),            this.paginatedList,            this.listHelper,            this.pagesize,            getAttributeMap(),            this.uid).writeTable(this.tableModel, this.getUid());        if (this.varTotals != null)        {            pageContext.setAttribute(this.varTotals, getTotals());        }    }    /**     * Get the column totals Map. If there is no varTotals defined, there are no totals.     * @return a Map of totals where the key is the column number and the value is the total for that column     */    public Map getTotals()    {        Map totalsMap = new HashMap();        if (this.varTotals != null)        {            List headers = this.tableModel.getHeaderCellList();            for (Iterator iterator = headers.iterator(); iterator.hasNext();)            {                HeaderCell headerCell = (HeaderCell) iterator.next();                if (headerCell.isTotaled())                {                    totalsMap.put("column" + (headerCell.getColumnNumber() + 1), new Double(headerCell.getTotal()));                }            }        }        return totalsMap;    }    /**     * Get the table model for this tag. Sometimes required by local tags that cooperate with DT. USE THIS METHOD WITH     * EXTREME CAUTION; IT PROVIDES ACCESS TO THE INTERNALS OF DISPLAYTAG, WHICH ARE NOT TO BE CONSIDERED STABLE PUBLIC     * INTERFACES.     * @return the TableModel     */    public TableModel getTableModel()    {        return this.tableModel;    }    /**     * Called by the setProperty tag to override some default behavior or text String.     * @param propertyName String property name     * @param propertyValue String property value     */    public void setProperty(String propertyName, String propertyValue)    {        this.properties.setProperty(propertyName, propertyValue);    }    /**     * @see javax.servlet.jsp.tagext.Tag#release()     */    public void release()    {        if (log.isDebugEnabled())        {            log.debug("[" + getUid() + "] release() called");        }        super.release();        // tag attributes        this.decoratorName = null;        this.defaultSortedColumn = -1;        this.defaultSortOrder = null;        this.export = false;        this.length = 0;        this.listAttribute = null;        this.localSort = true;        this.name = null;        this.offset = 0;        this.pagesize = 0;        this.partialList = false;        this.requestUri = null;        this.dontAppendContext = false;        this.sortFullTable = null;        this.excludedParams = null;        this.filteredRows = null;        this.uid = null;        this.keepStatus = false;        this.clearStatus = false;        this.form = null;    }    /**     * Returns the name.     * @return String     */    protected String getName()    {        return this.name;    }    /**     * encode a parameter name to be unique in the page using ParamEncoder.     * @param parameterName parameter name to encode     * @return String encoded parameter name     */    private String encodeParameter(String parameterName)    {        // paramEncoder has been already instantiated?        if (this.paramEncoder == null)        {            // use the id attribute to get the unique identifier            this.paramEncoder = new ParamEncoder(getUid());        }        return this.paramEncoder.encodeParameterName(parameterName);    }}

⌨️ 快捷键说明

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