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

📄 htmltablewriter.java

📁 dispalytag的源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    protected void writeEmptyListMessage(String emptyListMessage)    {        this.write(emptyListMessage);    }    /**     * Writes a HTML table column value to a JSP page.     * @see org.displaytag.render.TableWriterTemplate#writeColumnValue(java.lang.String,org.displaytag.model.Column)     */    protected void writeColumnValue(Object value, Column column)    {        this.write(value);    }    /**     * Writes an HTML message to a JSP page explaining that the row contains no data.     * @see org.displaytag.render.TableWriterTemplate#writeEmptyListRowMessage(java.lang.String)     */    protected void writeEmptyListRowMessage(String message)    {        this.write(message);    }    /**     * Writes an HTML table's column header to a JSP page.     * @see org.displaytag.render.TableWriterTemplate#writeTableHeader(org.displaytag.model.TableModel)     */    protected void writeTableHeader(TableModel model)    {        if (log.isDebugEnabled())        {            log.debug("[" + tableModel.getId() + "] getTableHeader called");        }        // open thead        write(TagConstants.TAG_THEAD_OPEN);        // open tr        write(TagConstants.TAG_TR_OPEN);        // no columns?        if (this.tableModel.isEmpty())        {            write(TagConstants.TAG_TH_OPEN);            write(TagConstants.TAG_TH_CLOSE);        }        // iterator on columns for header        Iterator iterator = this.tableModel.getHeaderCellList().iterator();        while (iterator.hasNext())        {            // get the header cell            HeaderCell headerCell = (HeaderCell) iterator.next();            if (headerCell.getSortable())            {                String cssSortable = this.properties.getCssSortable();                headerCell.addHeaderClass(cssSortable);            }            // if sorted add styles            if (headerCell.isAlreadySorted())            {                // sorted css class                headerCell.addHeaderClass(this.properties.getCssSorted());                // sort order css class                headerCell.addHeaderClass(this.properties.getCssOrder(this.tableModel.isSortOrderAscending()));            }            // append th with html attributes            write(headerCell.getHeaderOpenTag());            // title            String header = headerCell.getTitle();            // column is sortable, create link            if (headerCell.getSortable())            {                // creates the link for sorting                Anchor anchor = new Anchor(getSortingHref(headerCell), header);                // append to buffer                header = anchor.toString();            }            write(header);            write(headerCell.getHeaderCloseTag());        }        // close tr        write(TagConstants.TAG_TR_CLOSE);        // close thead        write(TagConstants.TAG_THEAD_CLOSE);        if (log.isDebugEnabled())        {            log.debug("[" + tableModel.getId() + "] getTableHeader end");        }    }    /**     * Generates the link to be added to a column header for sorting.     * @param headerCell header cell the link should be added to     * @return Href for sorting     */    private Href getSortingHref(HeaderCell headerCell)    {        // costruct Href from base href, preserving parameters        Href href = (Href) this.baseHref.clone();        if (this.tableModel.getForm() != null)        {            href = new PostHref(href, tableModel.getForm());        }        if (this.paginatedList == null)        {            // add column number as link parameter            if (!this.tableModel.isLocalSort() && (headerCell.getSortName() != null))            {                href.addParameter(encodeParameter(TableTagParameters.PARAMETER_SORT), headerCell.getSortName());                href.addParameter(encodeParameter(TableTagParameters.PARAMETER_SORTUSINGNAME), "1");            }            else            {                href.addParameter(encodeParameter(TableTagParameters.PARAMETER_SORT), headerCell.getColumnNumber());            }            boolean nowOrderAscending = true;            if (headerCell.getDefaultSortOrder() != null)            {                boolean sortAscending = SortOrderEnum.ASCENDING.equals(headerCell.getDefaultSortOrder());                nowOrderAscending = headerCell.isAlreadySorted()                    ? !this.tableModel.isSortOrderAscending()                    : sortAscending;            }            else            {                nowOrderAscending = !(headerCell.isAlreadySorted() && this.tableModel.isSortOrderAscending());            }            int sortOrderParam = nowOrderAscending ? SortOrderEnum.ASCENDING.getCode() : SortOrderEnum.DESCENDING                .getCode();            href.addParameter(encodeParameter(TableTagParameters.PARAMETER_ORDER), sortOrderParam);            // If user want to sort the full table I need to reset the page number.            // or if we aren't sorting locally we need to reset the page as well.            if (this.tableModel.isSortFullTable() || !this.tableModel.isLocalSort())            {                href.addParameter(encodeParameter(TableTagParameters.PARAMETER_PAGE), 1);            }        }        else        {            if (properties.getPaginationSkipPageNumberInSort())            {                href.removeParameter(properties.getPaginationPageNumberParam());            }            String sortProperty = headerCell.getSortProperty();            if (sortProperty == null)            {                sortProperty = headerCell.getBeanPropertyName();            }            href.addParameter(properties.getPaginationSortParam(), sortProperty);            String dirParam;            if (headerCell.isAlreadySorted())            {                dirParam = tableModel.isSortOrderAscending() ? properties.getPaginationDescValue() : properties                    .getPaginationAscValue();            }            else            {                dirParam = properties.getPaginationAscValue();            }            href.addParameter(properties.getPaginationSortDirectionParam(), dirParam);            if (paginatedList.getSearchId() != null)            {                href.addParameter(properties.getPaginationSearchIdParam(), paginatedList.getSearchId());            }        }        return href;    }    /**     * 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(this.tableModel.getId());        }        return this.paramEncoder.encodeParameterName(parameterName);    }    /**     * Generates table footer with links for export commands.     */    public void writeNavigationAndExportLinks()    {        // Put the page stuff there if it needs to be there...        if (this.properties.getAddPagingBannerBottom())        {            writeSearchResultAndNavigation();        }        // add export links (only if the table is not empty)        if (this.export && this.tableModel.getRowListPage().size() != 0)        {            writeExportLinks();        }    }    /**     * generates the search result and navigation bar.     */    public void writeSearchResultAndNavigation()    {        if ((this.paginatedList == null && this.pagesize != 0 && this.listHelper != null)            || (this.paginatedList != null))        {            // create a new href            Href navigationHref = (Href) this.baseHref.clone();            if (tableModel.getForm() != null)            {                navigationHref = new PostHref(navigationHref, tableModel.getForm());            }            write(this.listHelper.getSearchResultsSummary());            String pageParameter;            if (paginatedList == null)            {                pageParameter = encodeParameter(TableTagParameters.PARAMETER_PAGE);            }            else            {                pageParameter = properties.getPaginationPageNumberParam();                if ((paginatedList.getSearchId() != null)                    && (!navigationHref.getParameterMap().containsKey(properties.getPaginationSearchIdParam())))                {                    navigationHref.addParameter(properties.getPaginationSearchIdParam(), paginatedList.getSearchId());                }            }            write(this.listHelper.getPageNavigationBar(navigationHref, pageParameter));        }    }    /**     * Writes the formatted export links section.     */    private void writeExportLinks()    {        // Figure out what formats they want to export, make up a little string        Href exportHref = (Href) this.baseHref.clone();        StringBuffer buffer = new StringBuffer(200);        Iterator iterator = MediaTypeEnum.iterator();        while (iterator.hasNext())        {            MediaTypeEnum currentExportType = (MediaTypeEnum) iterator.next();            if (this.properties.getAddExport(currentExportType))            {                if (buffer.length() > 0)                {                    buffer.append(this.properties.getExportBannerSeparator());                }                exportHref.addParameter(encodeParameter(TableTagParameters.PARAMETER_EXPORTTYPE), currentExportType                    .getCode());                // export marker                exportHref.addParameter(TableTagParameters.PARAMETER_EXPORTING, "1");                Anchor anchor = new Anchor(exportHref, this.properties.getExportLabel(currentExportType));                buffer.append(anchor.toString());            }        }        String[] exportOptions = {buffer.toString()};        write(MessageFormat.format(this.properties.getExportBanner(), exportOptions));    }    /**     * create the open tag containing all the attributes.     * @return open tag string: <code>%lt;table attribute="value" ... ></code>     */    public String getOpenTag()    {        if (this.uid != null && attributeMap.get(TagConstants.ATTRIBUTE_ID) == null)        {            // we need to clone the attribute map in order to "fix" the html id when using only the "uid" attribute            Map localAttributeMap = (Map) attributeMap.clone();            localAttributeMap.put(TagConstants.ATTRIBUTE_ID, this.uid);            StringBuffer buffer = new StringBuffer();            buffer.append(TagConstants.TAG_OPEN).append(TagConstants.TABLE_TAG_NAME);            buffer.append(localAttributeMap);            buffer.append(TagConstants.TAG_CLOSE);            return buffer.toString();        }        // fast, no clone        StringBuffer buffer = new StringBuffer();        buffer.append(TagConstants.TAG_OPEN).append(TagConstants.TABLE_TAG_NAME);        buffer.append(attributeMap);        buffer.append(TagConstants.TAG_CLOSE);        return buffer.toString();    }    /**     * Utility method.     * @param string String     */    public void write(String string)    {        if (string != null)        {            try            {                out.write(string);            }            catch (IOException e)            {                throw new WrappedRuntimeException(getClass(), e);            }        }    }    public void writeTable(TableModel model, String id) throws JspException    {        super.writeTable(model, id);    }    /**     * Utility method.     * @param string String     */    public void write(Object string)    {        if (string != null)        {            try            {                out.write(string.toString());            }            catch (IOException e)            {                throw new WrappedRuntimeException(getClass(), e);            }        }    }}

⌨️ 快捷键说明

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