日期:2014-05-16 浏览次数:20366 次
package com.jframe.tag; /** * Title:自定列表列标签 * Description: * Copyright: Copyright (c) 2009-2011 * @author:jframe lixiaojie wangjun * @version 1.0 */ import javax.servlet.jsp.JspException; import javax.servlet.jsp.JspWriter; import javax.servlet.jsp.tagext.BodyContent; import javax.servlet.jsp.tagext.BodyTagSupport; import javax.servlet.jsp.tagext.DynamicAttributes; import javax.servlet.jsp.tagext.Tag; public class GtColumnTag extends BodyTagSupport implements DynamicAttributes { private static final long serialVersionUID = 2852493162447418830L; private String name; //数据集唯一标示 必填1 private String type; //数据类型 date int float string 默认是string private String index; //字段对应的"record的属性名". 根据index,GT-Grid就可以知道这一列 对应的时record哪个属性的值. private String initValue; //调用gt函数产生新的数据集 值例如:function(record){return record['english'] + record['math'];}} private String id; //每个列表组件都有一个id 该id在页面内唯一 private String header; //列显示名称 必填2 private String fieldName; //对应数据库字段 private String minWidth; //列最小宽度 private String width; //宽 private String align; //对其方式 private String sortable; //是否排序 ,只能设置一个列 ,true/false private String sortOrder; //排序规则asc desc private String hidden; //列是否被隐藏 private String printable; //列是否能打印 private String renderer; //调用gt的方法返回值 方法: function(value ,record,columnObj,grid,colNo,rowNo){return '<a href=".?no='+record['no']+'" >'+ record['name'] +' 的详细信息</a>';}} //例2: GT.Grid.mappingRenderer( {'U': '未知' , 'M':'男', 'F':'女'} , '未知' ) private String isCheckColumn;//是否是checkbox显示 必须设置GTTable属性selectRowByCheck : true, checkbox 名字是: gt_grid1_chk_no 规律 gt不变 grid1 是列表id chk不变 no 是列名 private String isCheckbox; //自定义checkbox private String dateFormat; //日期格式化 private String editType; private String options; private String validRule; private String validatorFunction; private String[] mappingArray; @Override public int doStartTag() throws JspException { if(this.index==null) { this.index=this.name; } if(this.id==null) { this.id=this.name; } if(this.fieldName!=null) { this.name=this.fieldName; } return EVAL_BODY_INCLUDE; } @Override public void doInitBody() throws JspException { // TODO Auto-generated method stub super.doInitBody(); } @Override public void setBodyContent(BodyContent b) { // TODO Auto-generated method stub super.setBodyContent(b); } @Override public int doAfterBody() throws JspException { // TODO Auto-generated method stub return super.doAfterBody(); } @Override public int doEndTag() throws JspException { try { StringBuffer columnDataStr=new StringBuffer(); StringBuffer columnConfigStr=new StringBuffer(); GtTag tableTag=(GtTag)this.getParent(); columnDataStr.append("{name:").append("'").append(name).append("'"); if(type!=null) { columnDataStr.append(",type:").append("'").append(type).append("'"); } columnDataStr.append(",index:").append("'").append(index).append("'"); if(initValue!=null) { columnDataStr.append(",initValue:").append(initValue); } if("true".equals(this.isCheckbox)) { columnDataStr.append(",initValue:").append("function(record){return '<input name=\\'id-checkbox\\' type=checkbox value=\\''+record['"+index+"']+'\\'>'} "); this.width="35"; sortable="false"; } columnDataStr.append("}"); columnConfigStr.append("{id:").append("'").append(id).append("'"); if("true".equals(this.isCheckbox)) { columnConfigStr.append(",header:").append("'").append("<input id=selectAllCheckbox type=checkbox onclick=selectAllCheckbox(this)>").append("'"); columnConfigStr.append(",title:").append("'全选'"); } else {