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

📄 columnstag.java

📁 分页查询控件 分页查询控件
💻 JAVA
字号:
package org.extremecomponents.table.tag;

import java.util.Iterator;
import java.util.List;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.extremecomponents.base.BaseModel;
import org.extremecomponents.table.bean.Column;
import org.extremecomponents.table.core.AutoGenerateColumns;
import org.extremecomponents.util.ExceptionUtils;

/**
 * @jsp.tag name="columns" display-name="ColumnsTag" body-content="JSP"
 *          description="Auto generate the columns."
 * 
 * @author Jeff Johnston
 */

public class ColumnsTag extends TagSupport {
    private static final long serialVersionUID = 7735172063399815570L;
    private static Log logger = LogFactory.getLog(ColumnsTag.class);
    
    private String autoGenerateColumns;

    /**
     * @jsp.attribute description="The fully qualified class name to add the columns."
     *                required="true" rtexprvalue="true"
     */
    public String getAutoGenerateColumns() {
        return autoGenerateColumns;
    }

    public void setAutoGenerateColumns(String autoGenerateColumns) {
        this.autoGenerateColumns = autoGenerateColumns;
    }

    public int doEndTag()
            throws JspException {
        try {
            TableTag tableTag = (TableTag) findAncestorWithClass(this, TableTag.class);
            BaseModel model = tableTag.getModel();
            
            if (model.getAutoGenerateColumns() == null) {
                Class classDefinition = Class.forName(autoGenerateColumns);
                model.setAutoGenerateColumns((AutoGenerateColumns)classDefinition.newInstance());
            }

            if (!tableTag.isIteratingBody()) {
                model.getAutoGenerateColumns().addColumns(model);
            } else {
                setColumnValues(tableTag);
            }

            return EVAL_PAGE;
        } catch (Exception e) {
            logger.error(ExceptionUtils.formatStackTrace(e));
            throw new JspException("ColumnsTag.doEndTag() Problem: " + ExceptionUtils.formatStackTrace(e));
        }
    }

    private void setColumnValues(TableTag tableTag)
            throws Exception {
        BaseModel model = tableTag.getModel();
        List columns = model.getColumnHandler().getColumns();
        Object bean = model.getTableHandler().getCurrentCollectionBean();
        Iterator iter = columns.iterator();
        while (iter.hasNext()) {
            Column column = (Column) iter.next();
            String property = column.getProperty();
            Object propertyValue = PropertyUtils.getProperty(bean, property);
            tableTag.addColumnValue(property, propertyValue, propertyValue);
        }
    }
}

⌨️ 快捷键说明

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