?? tabletag.java
字號:
?/*
* Copyright 2006-2007 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.ecside.tag;
import java.util.Iterator;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import org.apache.commons.lang.StringUtils;
import org.ecside.common.QueryResult;
import org.ecside.core.TableConstants;
import org.ecside.core.TableModel;
import org.ecside.core.TableModelImpl;
import org.ecside.core.bean.BaseBean;
import org.ecside.core.bean.Export;
import org.ecside.core.bean.Table;
import org.ecside.core.context.JspPageContext;
import org.ecside.easyda.DataAccessUtil;
import org.ecside.filter.ExportFilterUtils;
import org.ecside.table.interceptor.TableInterceptor;
import org.ecside.util.ExceptionUtils;
import org.ecside.view.html.BuilderConstants;
/**
* @author Wei Zijun
*
*/
public class TableTag extends BaseTagSupport implements TableInterceptor {
private static final long serialVersionUID = 1L;
private Table table;
private Object items;
private Iterator iterator;
private QueryResult queryResult;
protected String classic;
private String action;
private String insertAction;
private String updateAction;
private String deleteAction;
private String shadowRowAction;
private String alwaysShowExtend;
private String autoIncludeParameters;
private String border;
private String bufferView;
private String cellpadding;
private String cellspacing;
private String csvFileName;
private String editable;
private String excludeParameters;
private String filterable;
private String filterRowsCallback;
private String form;
private String height;
private String includeParameters;
private String interceptor;
private String listHeight;
private String listWidth;
private String locale;
private String maxRowsExported;
private String method;
private String minColWidth;
private String minWidth;
private String nearPageNum;
private String onInvokeAction;
private String pageSizeList;
private String paginationLocation;
private String pdfFileName;
private String resizeColWidth;
private String retrieveRowsCallback;
private String rowsDisplayed;
private String scope;
private String scrollList;
private String showExports;
private String showHeader;
private String showPrint;
private String showTitle;
private String showTooltips;
private String sortable;
private String sortRowsCallback;
private String state;
private String stateAttr;
private String style;
private String styleClass;
private String theme;
private String title;
private String toolbarContent;
private String toolbarLocation;
private String var;
private String view;
private String width;
private String xlsFileName;
private String oddRowBgColor;
private String evenRowBgColor;
private String generateScript;
private String useAjax;
private String doPreload;
private String excludeTool;
private String minHeight;
private String batchUpdate;
private String enctype;
// /**
// * @jsp.attribute description="Specify whether or not the table should use
// * pagination. Boolean value with the default being true."
// * required="false" rtexprvalue="true"
// */
// public void setShowPagination(String showPagination) {
// this.showPagination = showPagination;
// }
// /**
// * @jsp.attribute description="Specify whether or not the table should use
// * the exports. Boolean value with the default being true."
// * required="false" rtexprvalue="true"
// */
// public void setShowExports(String showExports) {
// this.showExports = showExports;
// }
// /**
// * @jsp.attribute description="Specify whether or not the table should use
// * the status bar. Boolean value with the default being true."
// * required="false" rtexprvalue="true"
// */
// public void setShowStatusBar(String showStatusBar) {
// this.showStatusBar = showStatusBar;
// }
public String getBatchUpdate() {
return batchUpdate;
}
public void setBatchUpdate(String batchUpdate) {
this.batchUpdate = batchUpdate;
}
public void addTableAttributes(TableModel model, Table table) {
}
public int doAfterBody() throws JspException {
Table table = model.getTable();
table.setAttribute(TableConstants.EXTEND_ATTRIBUTES,getExtendAttributesAsString());
resetExtendAttribute();
table.afterBody();
try {
if (queryResult!=null){
if (queryResult.getResultSet()!=null && queryResult.getResultSet().next()) {
model.queryResultExecute();
Object bean = DataAccessUtil.resultSetToMap(queryResult.getResultSet());
model.setCurrentRowBean(bean);
return EVAL_BODY_AGAIN;
}
}else{
if (iterator == null) {
iterator = model.execute().iterator();
}
if (iterator!=null && iterator.hasNext()) {
Object bean = iterator.next();
model.setCurrentRowBean(bean);
return EVAL_BODY_AGAIN;
}
}
} catch (Exception e) {
throw new JspException("TableTag.doAfterBody() Problem: "
+ ExceptionUtils.formatStackTrace(e));
}
return SKIP_BODY;
}
public void doCatch(Throwable e) throws Throwable {
throw new JspException("TableTag Problem: " + ExceptionUtils.formatStackTrace(e));
}
public void doFinally() {
if (queryResult!=null){
queryResult.closeAll();
queryResult=null;
}
items = null;
iterator = null;
model=null;
table = null;
}
public int doEndTag() throws JspException {
model.getTable().setAttribute(
TableConstants.EXTEND_ATTRIBUTES, getExtendAttributesAsString());
try {
pageContext.getOut().println(model.getViewData());
} catch (Exception e) {
// LogHandler.errorLog(logger, msg);
throw new JspException("TableTag.doEndTag() Problem: "
+ ExceptionUtils.formatStackTrace(e));
}finally{
doFinally();
}
return EVAL_PAGE;
}
public int doStartTag() throws JspException {
try {
// initialize the attributes
iterator = null;
pageContext.setAttribute(TableConstants.ROWCOUNT, "0");
// pageContext.setAttribute(ECSideConstants.TABLEMODEL_KEY, model);
// fire up the model with the context, preferences and messages
model = new TableModelImpl(new JspPageContext(pageContext), TagUtils.evaluateExpressionAsString("locale", this.locale, this, pageContext));
boolean isExported = ExportFilterUtils.isExported( model.getContext());
boolean isPrint="_print_".equals(ExportFilterUtils.getExportFileName( model.getContext()));
table = new Table(model);
table.setView(TagUtils.evaluateExpressionAsString("view", this.view, this, pageContext));
// if (!isExported || isPrint ) {
// make the table
table.setGenerateScript(TagUtils.evaluateExpressionAsBoolean("generateScript", this.generateScript, this, pageContext));
table.setUseAjax(TagUtils.evaluateExpressionAsBoolean("useAjax", this.useAjax, this, pageContext));
table.setDoPreload(TagUtils.evaluateExpressionAsBoolean("doPreload", this.doPreload, this, pageContext));
table.setClassic(TagUtils.evaluateExpressionAsBoolean("classic", this.classic, this, pageContext));
table.setAction(TagUtils.evaluateExpressionAsString("action", action, this, pageContext));
table.setEnctype(TagUtils.evaluateExpressionAsString("enctype", enctype, this, pageContext));
table.setInsertAction(TagUtils.evaluateExpressionAsString("insertAction", insertAction, this, pageContext));
table.setUpdateAction(TagUtils.evaluateExpressionAsString("updateAction", updateAction, this, pageContext));
table.setDeleteAction(TagUtils.evaluateExpressionAsString("deleteAction", deleteAction, this, pageContext));
table.setShadowRowAction(TagUtils.evaluateExpressionAsString("shadowRowAction", shadowRowAction, this, pageContext));
table.setBatchUpdate(TagUtils.evaluateExpressionAsBoolean("batchUpdate", this.batchUpdate, this, pageContext));
table.setAutoIncludeParameters(TagUtils.evaluateExpressionAsBoolean("autoIncludeParameters", this.autoIncludeParameters, this, pageContext));
table.setBorder(TagUtils.evaluateExpressionAsString("border", this.border, this, pageContext));
table.setBufferView(TagUtils.evaluateExpressionAsBoolean("bufferView", this.bufferView, this, pageContext));
table.setCellpadding(TagUtils.evaluateExpressionAsString("cellpadding", this.cellpadding, this, pageContext));
table.setCellspacing(TagUtils.evaluateExpressionAsString("cellspacing", this.cellspacing, this, pageContext));
table.setFilterable(TagUtils.evaluateExpressionAsBoolean("filterable", this.filterable, this, pageContext));
table.setFilterRowsCallback(TagUtils.evaluateExpressionAsString("filterRowsCallback", this.filterRowsCallback, this, pageContext));
table.setForm(TagUtils.evaluateExpressionAsString("form", this.form, this, pageContext));
table.setInterceptor(TagUtils.evaluateExpressionAsString("interceptor", this.interceptor, this, pageContext));
table.setItems(TagUtils.evaluateExpressionAsObject("items", this.items, this, pageContext));
table.setLocale(TagUtils.evaluateExpressionAsString("locale", this.locale, this, pageContext));
table.setMethod(TagUtils.evaluateExpressionAsString("method", this.method, this, pageContext));
table.setOnInvokeAction(TagUtils.evaluateExpressionAsString("onInvokeAction", this.onInvokeAction, this, pageContext));
table.setRetrieveRowsCallback(TagUtils.evaluateExpressionAsString("retrieveRowsCallback", this.retrieveRowsCallback, this, pageContext));
table.setRowsDisplayed(TagUtils.evaluateExpressionAsInt("rowsDisplayed", this.rowsDisplayed, this, pageContext));
table.setScope(TagUtils.evaluateExpressionAsString("scope", scope, this, pageContext));
table.setShowTitle(TagUtils.evaluateExpressionAsBoolean("showTitle", this.showTitle, this, pageContext));
table.setShowTooltips(TagUtils.evaluateExpressionAsBoolean("showTooltips", this.showTooltips, this, pageContext));
table.setSortRowsCallback(TagUtils.evaluateExpressionAsString("sortRowsCallback", this.sortRowsCallback, this, pageContext));
table.setSortable(TagUtils.evaluateExpressionAsBoolean("sortable", this.sortable, this, pageContext));
table.setState(TagUtils.evaluateExpressionAsString("state", this.state, this, pageContext));
table.setStateAttr(TagUtils.evaluateExpressionAsString("stateAttr", this.stateAttr, this, pageContext));
table.setStyle(TagUtils.evaluateExpressionAsString("style", style, this, pageContext));
table.setStyleClass(TagUtils.evaluateExpressionAsString("styleClass", this.styleClass, this, pageContext));
table.setTableId(TagUtils.evaluateExpressionAsString("tableId", getTableId(), this, pageContext));
table.setTheme(TagUtils.evaluateExpressionAsString("theme", this.theme, this, pageContext));
table.setTitle(TagUtils.evaluateExpressionAsString("title", this.title, this, pageContext));
table.setVar(TagUtils.evaluateExpressionAsString("var", this.var, this, pageContext));
table.setWidth(TagUtils.evaluateExpressionAsString("width", this.width, this, pageContext));
table.setExcludeTool(TagUtils.evaluateExpressionAsString("excludeTool", this.excludeTool, this, pageContext));
table.setOddRowBgColor(TagUtils.evaluateExpressionAsString("oddRowBgColor", this.oddRowBgColor, this, pageContext));
table.setEvenRowBgColor(TagUtils.evaluateExpressionAsString("evenRowBgColor", this.evenRowBgColor, this, pageContext));
table.setHeight(TagUtils.evaluateExpressionAsString("height", this.height, this, pageContext));
if (StringUtils.isBlank( table.getHeight()) ){
table.setHeight(TagUtils.evaluateExpressionAsString("listHeight", this.listHeight, this, pageContext));
}
table.setMinHeight(TagUtils.evaluateExpressionAsString("minHeight", this.minHeight, this, pageContext));
table.setListWidth(TagUtils.evaluateExpressionAsString("listWidth", this.listWidth, this, pageContext));
table.setScrollList(TagUtils.evaluateExpressionAsBoolean("scrollList", this.scrollList, this, pageContext));
table.setResizeColWidth(TagUtils.evaluateExpressionAsBoolean("resizeColWidth", this.resizeColWidth, this, pageContext));
table.setMinColWidth(TagUtils.evaluateExpressionAsInt("minColWidth", this.minColWidth, this, pageContext));
table.setNearPageNum(TagUtils.evaluateExpressionAsString("nearPageNum", this.nearPageNum, this, pageContext));
table.setMaxRowsExported(TagUtils.evaluateExpressionAsString("maxRowsExported", this.maxRowsExported, this, pageContext));
table.setToolbarContent( TagUtils.evaluateExpressionAsString("toolbarContent", this.toolbarContent, this, pageContext) );
table.setToolbarLocation( TagUtils.evaluateExpressionAsString("toolbarLocation", this.toolbarLocation, this, pageContext) );
table.setAlwaysShowExtend(TagUtils.evaluateExpressionAsString("alwaysShowExtend", this.alwaysShowExtend, this, pageContext));
table.setTagAttributes(TagUtils.evaluateExpressionAsString(TableConstants.TAG_ATTRIBUTES, this.tagAttributes, this, pageContext));
table.setIncludeParameters(TagUtils.evaluateExpressionAsString("includeParameters",this.includeParameters,this,pageContext));
table.setExcludeParameters(TagUtils.evaluateExpressionAsString("excludeParameters",this.excludeParameters,this,pageContext));
table.setShowHeader(TagUtils.evaluateExpressionAsBoolean("showHeader",this.showHeader,this,pageContext));
table.setPageSizeList(TagUtils.evaluateExpressionAsString("pageSizeList",this.pageSizeList,this,pageContext));
table.setMinWidth(TagUtils.evaluateExpressionAsString("minWidth", this.minWidth, this, pageContext));
table.setEditable(TagUtils.evaluateExpressionAsBoolean("editable", this.editable, this, pageContext));
if ( StringUtils.isBlank(table.getAction()) ) {
table.setAction(((HttpServletRequest)pageContext.getRequest()).getRequestURL().toString());
}
table.setAttribute(TableConstants.XLS_FILE, TagUtils
.evaluateExpressionAsString(TableConstants.XLS_FILE,
this.xlsFileName, this, pageContext));
table.setAttribute(TableConstants.CSV_FILE, TagUtils
.evaluateExpressionAsString(TableConstants.CSV_FILE,
this.csvFileName, this, pageContext));
table.setAttribute(TableConstants.PDF_FILE, TagUtils
.evaluateExpressionAsString(TableConstants.PDF_FILE,
this.pdfFileName, this, pageContext));
table.setAttribute(TableConstants.SHOW_PRINT, TagUtils
.evaluateExpressionAsString(TableConstants.SHOW_PRINT,
this.showPrint, this, pageContext));
exportsMaker(model,table);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -