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

📄 columntag.java

📁 分页查询控件 分页查询控件
💻 JAVA
字号:
/* * Copyright 2004 original author or authors. * * 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.extremecomponents.table.tag;import javax.servlet.jsp.JspException;import javax.servlet.jsp.tagext.BodyTagSupport;import org.apache.commons.beanutils.PropertyUtils;import org.apache.commons.lang.StringUtils;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager;import org.extremecomponents.base.BaseModel;import org.extremecomponents.table.bean.Attributes;import org.extremecomponents.table.bean.Column;import org.extremecomponents.util.ExceptionUtils;import org.extremecomponents.util.ExtremeUtils;/** * @jsp.tag name="column" display-name="ColumnTag" body-content="JSP" *          description="The container which holds all the column specific *          information. A copy of each column will be fed to the Model." *  * @author Jeff Johnston */public class ColumnTag extends BodyTagSupport implements ExtendedAttributes {    private static Log logger = LogFactory.getLog(ColumnTag.class);    private static final long serialVersionUID = -3289986079687803742L;    private String property;    private Object value;    private String title;    private String styleClass;    private String headerClass;    private String cell;    private String filterCell;    private String headerCell;    private String format;    private String parse;    private String width;    private String style;    private String showTotal;    private String filterable;    private String sortable;    private String exportable;    private BaseModel model;    /**     * @jsp.attribute description="The bean attribute to use for the column."     *                required="true" rtexprvalue="true"     */    public String getProperty() {        return ColumnTagUtils.getProperty(model, property);    }    public void setProperty(String property) {        this.property = property;    }    /**     * @jsp.attribute description="The value for the column. If the value     *                attribute is not specifed then it will be retrieved     *                automatically by using the property attribute. The value     *                can also be defined within the column body."     *                required="false" rtexprvalue="true"     */    public Object getValue() {        return value;    }    public void setValue(Object value) {        this.value = value;    }    /**     * @jsp.attribute description="The verbage that will display on the table     *                column header. If title is not specified then it will     *                default to the name of the property, changing the     *                camelcase syntax to separate words." required="false"     *                rtexprvalue="true"     */    public String getTitle() {        String result = evaluateExpressionAsString("title", title);        return ColumnTagUtils.getTitle(model, result, getProperty());    }    public void setTitle(String title) {        this.title = title;    }    /**     * @jsp.attribute description="The css class style sheet." required="false"     *                rtexprvalue="true"     */    public String getStyleClass() {        return ColumnTagUtils.getStyleClass(model, styleClass);    }    public void setStyleClass(String styleClass) {        this.styleClass = styleClass;    }    /**     * @jsp.attribute description="The css class style sheet used to define what     *                the table header row column looks like. If all the columns     *                are defined the same then you may want to use the table     *                headerClass attribute." required="false"     *                rtexprvalue="true"     */    public String getHeaderClass() {        return ColumnTagUtils.getHeaderClass(model, headerClass);    }    public void setHeaderClass(String headerClass) {        this.headerClass = headerClass;    }    /**     * @jsp.attribute description="Displays the column. The valid values are     *                display, currency, number, and date. The default value is     *                display. The cell can also be a fully qualified class name     *                to a custom cell. Be sure to implement the Cell interface     *                or extend BaseCell if making a custom cell."     *                required="false" rtexprvalue="true"     */    public String getCell() {        return ColumnTagUtils.getCell(model, cell);    }    public void setCell(String cell) {        this.cell = cell;    }    /**     * @jsp.attribute description="Displays the filter column. The valid values     *                are filter and droplist. The default is filter. The cell     *                can also be a fully qualified class name to a custom     *                cell." required="false" rtexprvalue="true"     */    public String getFilterCell() {        return ColumnTagUtils.getFilterCell(model, filterCell);    }    public void setFilterCell(String filterCell) {        this.filterCell = filterCell;    }    /**     * @jsp.attribute description="Displays the header column. The default is     *                header. The cell can also be a fully qualified class name     *                to a custom cell." required="false" rtexprvalue="true"     */    public String getHeaderCell() {        return ColumnTagUtils.getHeaderCell(model, headerCell);    }    public void setHeaderCell(String headerCell) {        this.headerCell = headerCell;    }    /**     * @jsp.attribute description="The specific way the column is displayed. For     *                instance if used with a date cell then the format can be     *                MM/dd/yyyy." required="false" rtexprvalue="true"     */    public String getFormat() {        return ColumnTagUtils.getFormat(model, format, getCell());    }    public void setFormat(String format) {        this.format = format;    }    /**     * @jsp.attribute description="Used if the format needs to be interpreted so     *                the correct cell can be resolved. For instance, a date     *                needs to be parsed in the specific format, such as     *                MM-dd-yyyy." required="false" rtexprvalue="true"     */    public String getParse() {        return ColumnTagUtils.getParse(model, parse, getCell());    }    public void setParse(String parse) {        this.parse = parse;    }    /**     * @jsp.attribute description="Specify whether or not the column should be     *                filterable. Acceptable values are true or false."     *                required="false" rtexprvalue="true"     */    public String getFilterable() {        return ColumnTagUtils.getFilterable(model, filterable);    }    public void setFilterable(String filterable) {        this.filterable = filterable;    }    /**     * @jsp.attribute description="Specify whether or not the column should be     *                sortable. The acceptable values are true or false."     *                required="false" rtexprvalue="true"     */    public String getSortable() {        return ColumnTagUtils.getSortable(model, sortable);    }    public void setSortable(String sortable) {        this.sortable = sortable;    }    /**     * @jsp.attribute description="Specify the column width." required="false"     *                rtexprvalue="true"     */    public String getWidth() {        return ColumnTagUtils.getWidth(model, width);    }    public void setWidth(String width) {        this.width = width;    }    /**     * @jsp.attribute description="The css inline style sheet." required="false"     *                rtexprvalue="true"     */    public String getStyle() {        return ColumnTagUtils.getStyle(model, style);    }    public void setStyle(String style) {        this.style = style;    }    /**     * @jsp.attribute description="Specify whether or not the column should be     *                exportable. The acceptable values are true or false."     *                required="false" rtexprvalue="true"     */    public String getExportable() {        return ColumnTagUtils.getExportable(model, exportable);    }    public void setExportable(String exportable) {        this.exportable = exportable;    }    /**     * @jsp.attribute description="Specify whether or not the total for the     *                column should be displayed. The acceptable values are true     *                or false." required="false" rtexprvalue="true"     */    public String getShowTotal() {        return ColumnTagUtils.getShowTotal(model, showTotal);    }    public void setShowTotal(String showTotal) {        this.showTotal = showTotal;    }        private String evaluateExpressionAsString(String attributeName, String attribute) {        try {            if (attribute != null) {                attribute = (String) ExpressionEvaluatorManager.evaluate(attributeName, attribute, String.class, this, pageContext);            }        } catch (JspException e) {            logger.error("Could not resolve EL for [" + attributeName + "] - "+ ExceptionUtils.formatStackTrace(e));        }                return attribute;    }    /**     * Get the value for the column. First look to see if it displayed in the     * body of the column. If it is not in the body, then use the value     * attribute. If the value attribute is not specified then use the property     * attribute to find the value in the bean. Note: Weblogic will always     * return a bodyContent so do additional checking.     */    public Object getColumnValue(Object propertyValue)            throws JspException {        Object result = value;        if (result == null && bodyContent != null) {            result = getBodyContent().getString();        }        if (result != null) {            result = (Object) ExpressionEvaluatorManager.evaluate("result", result.toString(), Object.class, this,                    pageContext);        }        if (result == null                 || (result != null && result instanceof String && StringUtils.isBlank(result.toString()))) {            result = propertyValue;        }        return result;    }    public Object getColumnPropertyValue()            throws JspException {        Object result = null;        try {            Object bean = model.getTableHandler().getCurrentCollectionBean();            if (ExtremeUtils.isBeanPropertyReadable(bean, getProperty())) {                result = PropertyUtils.getProperty(bean, getProperty());            }        } catch (Exception e) {            String collection = model.getTableHandler().getTable().getCollection();            String message = "Could not find the property " + getProperty() + " in " + collection;            logger.error(message);            throw new JspException(message);        }        return result;    }    public int doStartTag()            throws JspException {        TableTag tableTag = (TableTag) findAncestorWithClass(this, TableTag.class);        model = tableTag.getModel();        if (!tableTag.isIteratingBody()) // first pass through skip the body        {            return SKIP_BODY;        }        return EVAL_BODY_BUFFERED;    }    /**     * Must make a copy of the column because this tag may be reused. Send the     * copy up to the Model.     */    public int doEndTag()            throws JspException {        TableTag tableTag = (TableTag) findAncestorWithClass(this, TableTag.class);        if (tableTag.isIteratingBody()) {            Object propertyValue = getColumnPropertyValue();            tableTag.addColumnValue(getProperty(), getColumnValue(propertyValue), propertyValue);        } else {            Column column = new Column();            column.addAttribute(Column.PROPERTY, getProperty());            column.addAttribute(Column.CELL, getCell());            column.addAttribute(Column.TITLE, getTitle());            column.addAttribute(Column.STYLE_CLASS, getStyleClass());            column.addAttribute(Column.HEADER_CLASS, getHeaderClass());            column.addAttribute(Column.FILTER_CELL, getFilterCell());            column.addAttribute(Column.HEADER_CELL, getHeaderCell());            column.addAttribute(Column.FORMAT, getFormat());            column.addAttribute(Column.PARSE, getParse());            column.addAttribute(Column.SORTABLE, getSortable());            column.addAttribute(Column.FILTERABLE, getFilterable());            column.addAttribute(Column.WIDTH, getWidth());            column.addAttribute(Column.STYLE, getStyle());            column.addAttribute(Column.EXPORTABLE, getExportable());            column.addAttribute(Column.SHOW_TOTAL, getShowTotal());            addExtendedAttributes(column);            tableTag.addColumn(column);        }                if (bodyContent != null) {            bodyContent.clearBody();        }        return EVAL_PAGE;    }    public void addExtendedAttributes(Attributes attributes)            throws JspException {    }    public void release() {        property = null;        value = null;        title = null;        styleClass = null;        headerClass = null;        cell = null;        format = null;        parse = null;        filterable = null;        sortable = null;        width = null;        style = null;        exportable = null;        super.release();    }}

⌨️ 快捷键说明

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