📄 columntag.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.List;
import java.util.Map;
import javax.servlet.jsp.JspException;
import org.apache.commons.lang.StringUtils;
import org.ecside.core.ECSideConstants;
import org.ecside.core.TableConstants;
import org.ecside.core.TableModel;
import org.ecside.core.TableModelUtils;
import org.ecside.core.bean.BaseBean;
import org.ecside.core.bean.Column;
import org.ecside.filter.ExportFilterUtils;
import org.ecside.table.interceptor.ColumnInterceptor;
import org.ecside.util.ECSideUtils;
import org.ecside.util.ExceptionUtils;
/**
* @author Wei Zijun
*
*/
/**
* @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."
*
*/
public class ColumnTag extends BaseBodyTagSupport implements ColumnInterceptor {
/**
*
*/
// private Column column;
private static final long serialVersionUID = 1L;
private String alias;
private String calc;
private String calcspan;
private String calcSpan;
private String calcTitle;
private String cell;
private String cellEdit;
private String cellName;
private String cellValue;
private String ellipsis;
private String escapeAutoFormat;
private String filterable;
private String filterCell;
private String filterClass;
private Object filterOptions;
private String filterStyle;
private String format;
private String group;
private String headerCell;
private String headerClass;
private String headerSpan;
private String headerStyle;
private String headerStyleClass;
private String interceptor;
private Object mappingDefaultKey;
private Object mappingDefaultValue;
private Object mappingItem;
private String minWidth;
private String nowrap;
private String onclick;
private String ondblclick;
private String onmouseout;
private String onmouseover;
private String parse;
private String property;
private String resizeColWidth;
private String sortable;
private String style;
private String styleClass;
private String title;
private String viewsAllowed;
private String viewsDenied;
private String width;
private String columnId;
private String editTemplate;
private String editEvent;
private String editable;
private String tipTitle;
public void addColumnAttributes(TableModel model, Column column) {
}
public int doStartTag() throws JspException {
model = TagUtils.getModel(this);
// Column column=null;
// if (!TagUtils.isIteratingBody(this)) {
// column = new Column(model);
//// return SKIP_BODY;
// }else{
// column = model.getColumnHandler().getColumnByAlias(TableModelUtils.getAlias(alias, property));
// }
return EVAL_BODY_BUFFERED;
}
public int doEndTag() throws JspException {
boolean isExported = ExportFilterUtils.isExported( model.getContext());
boolean isPrint="_print_".equals(ExportFilterUtils.getExportFileName( model.getContext()));
Column column=null;
try {
if (!TagUtils.isIteratingBody(this)) {
column = new Column(model);
column.setAlias(TagUtils.evaluateExpressionAsString("alias", this.alias, this, pageContext));
column.setProperty(TagUtils.evaluateExpressionAsString("property", this.property, this, pageContext) );
column.setCalc(TagUtils.evaluateExpressionAsString("calc", this.calc, this, pageContext));
column.setCalcTitle(TagUtils.evaluateExpressionAsString("calcTitle", calcTitle, this, pageContext));
column.setCell(TagUtils.evaluateExpressionAsString("cell", this.cell, this, pageContext));
column.setEscapeAutoFormat(TagUtils.evaluateExpressionAsBoolean("escapeAutoFormat", this.escapeAutoFormat, this, pageContext));
column.setFormat(TagUtils.evaluateExpressionAsString("format", this.format, this, pageContext));
column.setInterceptor(TagUtils.evaluateExpressionAsString("interceptor", this.interceptor, this, pageContext));
column.setParse(TagUtils.evaluateExpressionAsString("parse", this.parse, this, pageContext));
column.setTitle(TagUtils.evaluateExpressionAsString("title", this.title, this, pageContext));
//TODO:
TagUtils.initExpression("cellValue",ECSideUtils.convertString(getColumnValue(),null), column);
column.setStyle(TagUtils.evaluateExpressionAsString("style", this.style, this, pageContext));
TagUtils.initExpression("style",column.getStyle(), column);
column.setViewsAllowed(TagUtils.evaluateExpressionAsString("viewsToAllow", this.viewsAllowed, this, pageContext));
column.setViewsDenied(TagUtils.evaluateExpressionAsString("viewsToDeny", this.viewsDenied, this, pageContext));
column.setFilterable(TagUtils.evaluateExpressionAsBoolean("filterable", this.filterable, this, pageContext));
column.setFilterCell(TagUtils.evaluateExpressionAsString("filterCell", this.filterCell, this, pageContext));
column.setFilterClass(TagUtils.evaluateExpressionAsString("filterClass", this.filterClass, this, pageContext));
column.setFilterOptions(TagUtils.evaluateExpressionAsObject("filterOptions", this.filterOptions, this, pageContext));
column.setFilterStyle(TagUtils.evaluateExpressionAsString("filterStyle", this.filterStyle, this, pageContext));
column.setHeaderCell(TagUtils.evaluateExpressionAsString("headerCell", this.headerCell, this, pageContext));
column.setHeaderClass(TagUtils.evaluateExpressionAsString("headerClass", this.headerClass, this, pageContext));
column.setHeaderStyle(TagUtils.evaluateExpressionAsString("headerStyle", this.headerStyle, this, pageContext));
column.setHeaderStyleClass(TagUtils.evaluateExpressionAsString("headerStyleClass", this.headerStyleClass, this, pageContext));
column.setSortable(TagUtils.evaluateExpressionAsBoolean("sortable", this.sortable, this, pageContext));
column.setEditable(TagUtils.evaluateExpressionAsBoolean("editable", this.editable, this, pageContext));
String widthT=TagUtils.evaluateExpressionAsString("width", this.width, this, pageContext);
if (!model.getTable().isClassic()) {
int tempWidth=0;
if (StringUtils.isBlank(widthT)){
widthT=""+ECSideConstants.DEFAULT_COLUMNWIDTH;
//widthT="";
tempWidth=ECSideConstants.DEFAULT_COLUMNWIDTH;
}else{
try{
if (widthT.indexOf("%")>0){
tempWidth=ECSideConstants.DEFAULT_COLUMNWIDTH;
}else if(widthT.toLowerCase().endsWith("px")){
tempWidth=Integer.parseInt(widthT.substring(0,widthT.length()-2));
}else{
tempWidth=Integer.parseInt(widthT);
}
}catch(Exception e){
tempWidth=ECSideConstants.DEFAULT_COLUMNWIDTH;
}
}
model.getTable().addTotalWidth(tempWidth);
}
column.setWidth(widthT);
column.setEllipsis(TagUtils.evaluateExpressionAsBoolean("ellipsis", this.ellipsis, this, pageContext));
column.setResizeColWidth(TagUtils.evaluateExpressionAsBoolean("resizeColWidth", this.resizeColWidth, this, pageContext));
column.setMinWidth(TagUtils.evaluateExpressionAsInt("minWidth", this.minWidth, this, pageContext));
column.setEditEvent(TagUtils.evaluateExpressionAsString("editEvent", this.editEvent, this, pageContext));
column.setEditTemplate(TagUtils.evaluateExpressionAsString("editTemplate", this.editTemplate, this, pageContext));
// column.setCellName(TagUtils.evaluateExpressionAsString("cellName", this.cellName, this, pageContext));
column.setNowrap(TagUtils.evaluateExpressionAsString("nowrap", this.nowrap, this, pageContext));
column.setGroup(TagUtils.evaluateExpressionAsString("group", this.group, this, pageContext));
if (StringUtils.isBlank(this.headerSpan)){
column.setHeaderSpan(-1);
}else{
column.setHeaderSpan(TagUtils.evaluateExpressionAsInt("headerSpan", this.headerSpan, this, pageContext));
}
if (StringUtils.isNotBlank(this.calcSpan)){
Column fcolumn;
List columns=TagUtils.getModel(this).getColumnHandler().getColumns();
if (columns==null || columns.size()<1 || columns.get(0)==null){
fcolumn=column;
}else{
fcolumn=(Column)columns.get(0);
}
fcolumn.setCalcSpan(TagUtils.evaluateExpressionAsInt("calcSpan", this.calcSpan, this, pageContext));
}
column.setTagAttributes(TagUtils.evaluateExpressionAsString(TableConstants.TAG_ATTRIBUTES, this.tagAttributes, this, pageContext));
// column.setAttribute(TDTableConstants.EXTEND_ATTRIBUTES,getExtendAttributesAsString());
// resetExtendAttribute();
addColumnAttributes(model, column);
model.getColumnHandler().addColumn(column);
} else {
column = model.getColumnHandler().getColumnByAlias(TableModelUtils.getAlias(alias, property));
if (column != null) { // null if view not allowed
Object currentBean = TagUtils.getModel(this).getCurrentRowBean();
// Object previousBean = TagUtils.getModel(this).getPreviousRowBean();
Object propertyValue = TableModelUtils.getColumnPropertyValue(currentBean, property);
Object cellValue;
// column.setCellValue(TagUtils.evaluateExpressionAsString("cellValue", this.cellValue, this, pageContext));
column.setCellValue(TagUtils.evaluateExpressionAsString("cellValue", this.cellValue, this, pageContext));
cellValue=TagUtils.runExpression("cellValue",column,currentBean);
// column.setCellValue(propertyValue==null?null:String.valueOf(propertyValue));
if (cellValue==null){
cellValue=getColumnValue(propertyValue);
}
if (propertyValue==null){
propertyValue=cellValue;
}
// Object[] expressionPropertys=column.getExpressionPropertys("cellValue");
// if (expressionPropertys!=null){
// GirdExpression expression=column.getExpression("cellValue");
// for (int i=0;i<expressionPropertys.length;i++){
// String ep=(String)expressionPropertys[i];
// expression.setArgument(ep, TableModelUtils.getColumnPropertyValue(currentBean, ep));
// }
// cellValue=expression.call();
// if (propertyValue==null){
// propertyValue=cellValue;
// }
// }else{
// cellValue=getColumnValue(propertyValue);
// }
column.setTipTitle(TagUtils.evaluateExpressionAsString("tipTitle", this.tipTitle, this, pageContext));
Object preCellValue=column.getPreCellValue();
// if (previousBean!=null){
// prePropertyValue=TableModelUtils.getColumnPropertyValue(previousBean, property);
//
// if ("hide".equalsIgnoreCase(column.getGroup())){
// if (propertyValue!=null && propertyValue.equals(prePropertyValue)){
// cellValue="";
// }
// }
// }
boolean hideCell=false;
boolean isGroup=false;
if ("true".equalsIgnoreCase(column.getGroup())){
isGroup=true;
}
if (isGroup){
column.setPreCellValue(cellValue);
if (cellValue!=null && cellValue.equals(preCellValue)){
cellValue="";
column.setStyle("display:none;");
hideCell=true;
// column.setStyle(column.getStyle()+";display:none;");
}
}
column.setValue(cellValue);
column.setPropertyValue(propertyValue);
if (!hideCell){
column.setOnclick(TagUtils.evaluateExpressionAsString(TableConstants.ON_CLICK, this.onclick, this, pageContext));
column.setOndblclick(TagUtils.evaluateExpressionAsString(TableConstants.ON_DOUBLE_CLICK, this.ondblclick, this, pageContext));
column.setOnmouseover(TagUtils.evaluateExpressionAsString(TableConstants.ON_MOUSE_OVER, this.onmouseover, this, pageContext));
column.setOnmouseout(TagUtils.evaluateExpressionAsString(TableConstants.ON_MOUSE_OUT, this.onmouseout, this, pageContext));
String styleClassName=TagUtils.evaluateExpressionAsString("styleClass", this.styleClass, this, pageContext);
if (isGroup){
styleClassName= "groupColumn " +ECSideUtils.convertString(styleClassName, "");
}
column.setStyleClass(styleClassName);
String style=ECSideUtils.convertString(TagUtils.runExpression("style",column,currentBean),null);
if (style==null) {
column.setStyle(TagUtils.evaluateExpressionAsString("style", this.style, this, pageContext));
}else{
column.setStyle(style);
}
}
// column.setCellValue(TagUtils.evaluateExpressionAsString("cellValue", this.cellValue, this, pageContext));
column.setTagAttributes(TagUtils.evaluateExpressionAsString(TableConstants.TAG_ATTRIBUTES, this.tagAttributes, this, pageContext));
column.setId(TagUtils.evaluateExpressionAsString("columnId", columnId, this, pageContext));
modifyColumnAttributes(model, column);
model.getColumnHandler().modifyColumnAttributes(column);
model.getViewHandler().addColumnValueToView(column);
// model.setPreviousRowBean(currentBean);
}
//
}
if (bodyContent != null) {
bodyContent.clearBody();
}
// column.setAttribute(TDTableConstants.EXTEND_ATTRIBUTES,"");
} catch (Exception e) {
throw new JspException("ColumnTag.doEndTag() Problem: " + ExceptionUtils.formatStackTrace(e));
}finally{
doFinally();
}
return EVAL_PAGE;
}
public void doFinally() {
super.doFinally();
}
protected Object getColumnValue() throws JspException {
Object result = getValue();
if (result == null && bodyContent != null) {
result = getBodyContent().getString();
}
if (result != null) {
result = TagUtils.evaluateExpressionAsObject("result", result, this, pageContext);
}
return result;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -