第一步编写DataGridColumnTag(表格列)
public class DataGridColumnTag extends BaseGeneralVarTagBinding{ @Override public void render() { } }
第二步编写DataGridOptTag(操作列)
public class DataGridOptTag extends BaseGeneralVarTagBinding{ @Override public void render(){ } }
第三步编写DataGridTag(表格属性)
/** * @ClassName: DateGridTag * @Description:表格标签 * @author 杨力 * @date 2016年11月28日 下午9:39:31 * */ public class DataGridTag extends BaseGeneralVarTagBinding{ public List<DataGridOpt> columnOptList = new ArrayList<>();//操作列集合 public List<DataGridColumn> columnImgList = new ArrayList<>();//操作列集合 protected List<DataGridColumnReplace> columnValueList = new ArrayList<DataGridColumnReplace>();// 值替换集合 protected List<DataGridColumn> columnQueryList = new ArrayList<DataGridColumn>();// 查询列集合 public String tableName;//表名 @Override public void render() { this.getBodyContent(); DataGrid dataGrid = initParam(DataGrid.class, super.args); tableName = dataGrid.getId(); StringBuffer buffer = new StringBuffer(); StringBuffer queryBuffer = new StringBuffer(); try { setTableBegin(dataGrid, buffer); List<TagNestContext> columnList = getColumn(); for (TagNestContext column : columnList) { if("tr".equals(column.getTags()[0])){ setColumn(initParam(DataGridColumn.class, column.getTags()), buffer); }else if("opt".equals(column.getTags()[0])){ columnOptList.add(initParam(DataGridOpt.class, column.getTags())); } } setTableEnd(dataGrid, buffer); buffer.append("<script type=\"text/javascript\">"); setSearchForm(buffer,dataGrid);//设置查询 setOptColumn(buffer);//组装操作列 setReplace(buffer);//组装替换列 getImgColumn(buffer);//组装图片列 buffer.append("</script>"); setSearchPage(dataGrid, queryBuffer);//设置搜索表单 queryBuffer.append(buffer); ctx.byteWriter.writeString(queryBuffer.toString()); clearList();//清理集合 } catch (IOException e) { e.printStackTrace(); } } public void setSearchPage(DataGrid dataGrid,StringBuffer buffer){ if(dataGrid.isShowSearch()){ buffer.append("<div class=\"row\" style=\"padding-left:0px\">\n"); buffer.append("<form id=\"form_"+tableName+"\">\n"); buffer.append("<div class=\"col-sm-12 col-xs-12\">\n"); for (DataGridColumn columnQuery : columnQueryList) { buffer.append("<div class=\"col-sm-2 col-xs-2\" style=\"padding-left:0px\">"); if (ToolString.isNotEmpty(columnQuery.getReplace())) { buffer.append("<select name=\""+ columnQuery.getField()+ "\""); buffer.append(" id=\""+ columnQuery.getField()+"\""); buffer.append(" class=\"input-sm form-control input-s-sm inline\"> "); buffer.append("<option value =\"\" >---请选择---</option>"); String[] test = columnQuery.getReplace().split(","); String text = ""; String value = ""; for (String string : test) { text = string.split("_")[0]; value = string.split("_")[1]; buffer.append("<option value =\"" + value + "\">" + text + "</option>"); } buffer.append("</select>"); } else if (ToolString.isNotEmpty(columnQuery.getDict())) { List<TType> typeList = CacheKit.get(Constant.CACHE_NAME_SYSTEM_TYPE, ThreadParamInit.CACHESTART_TYPE + columnQuery.getDict()); buffer.append("<select name=\""+ columnQuery.getField()+"\""); buffer.append(" id=\""+ columnQuery.getField()+"\""); buffer.append(" class=\"input-sm form-control input-s-sm inline\"> "); buffer.append("<option value =\"\" >---请选择---</option>"); for (TType type : typeList) { buffer.append("<option value=\"" + type.getStr("code") + "\">"); buffer.append(type.getStr("name")); buffer.append(" </option>"); } buffer.append("</select>"); }else if("group".equals(columnQuery.getQueryMode())){ buffer.append("<input class=\"easyui-datetimebox\" type=\"text\" id=" + columnQuery.getField() + "/ name=\"" + columnQuery.getField() + "_begin\" style=\"width: 100px;height:25px;\" data-options=\"showSeconds:false\" />"); buffer.append("<span style=\"display:-moz-inline-box;display:inline-block;width: 8px;text-align:right;\">~</span>"); buffer.append("<input class=\"easyui-datetimebox\" type=\"text\" id=" + columnQuery.getField() + "_end name=\"" + columnQuery.getField() + "_end\" style=\"width: 100px;height:25px;\" data-options=\"showSeconds:false\" />"); }else{ buffer.append("<input placeholder=\"请输入"+columnQuery.getText()+"\" class=\"input-sm form-control input-s-sm\" maxlength=\"20\" id=\""+columnQuery.getField()+"\" name=\""+columnQuery.getField()+"\" type=\"text\">"); } buffer.append("</div>"); } buffer.append("<div class=\"pull-right\">\n"); buffer.append("<button type=\"button\" onclick=\"clean_"+tableName+"()\" class=\"btn btn-white btn-sm\"><i class=\"fa fa-refresh\"></i> 重置</button>\n"); buffer.append("</div>\n"); buffer.append("<div class=\"col-md-3 col-sm-3 col-xs-3 pull-right\">"); buffer.append("<div class=\"input-group m-b-xs\">\n"); buffer.append("<input type=\"text\" name=\"searchName\" maxlength=\"15\" placeholder=\"请输入关键词\" class=\"input-sm form-control input-s-sm\"> <span class=\"input-group-btn\">\n"); buffer.append("<button onclick=\"search_"+tableName+"()\" type=\"button\" class=\"btn btn-sm btn-primary\"><i class=\"fa fa-search\"></i>搜索</button> </span>\n"); buffer.append("</div>\n"); buffer.append("</div>\n"); buffer.append("</div>\n"); buffer.append("</form>\n"); buffer.append("</div>"); } } public void setTableBegin(DataGrid dataGrid,StringBuffer buffer){ buffer.append("<table fit=\"true\" id=\""+dataGrid.getId()+"\" toolbar=\"#toolbar_"+tableName+"\" "); //判断是否需要初始化 if(dataGrid.isInitGrid()){ if(dataGrid.isTreeTable()){ buffer.append("class=\"easyui-treegrid\" "); }else{ buffer.append("class=\"easyui-datagrid\" "); } } buffer.append("style=\"width:100%\""); buffer.append("data-options=\""); buffer.append("url:'"+dataGrid.getUrl()+"'"); if(dataGrid.isTreeTable()){ buffer.append(",idField:'"+dataGrid.getIdField()+"'"); buffer.append(",treeField:'"+dataGrid.getTreeField()+"'"); } buffer.append(",fitColumns:true"); buffer.append(",singleSelect:"+dataGrid.isSingleSelect()); buffer.append(",pageSize:"+dataGrid.getPageSize()); buffer.append(",pageList:["+dataGrid.getPageSize()+","+(dataGrid.getPageSize()+10)+","+(dataGrid.getPageSize()+20)+","+(dataGrid.getPageSize()+30)+"]"); buffer.append(",pagination:"+dataGrid.isPagination()); buffer.append("\""); buffer.append("><thead><tr>"); if(dataGrid.isCheckbox()){ buffer.append("<th data-options=\"field:'"+dataGrid.getIdField()+"',checkbox:true\"></th>"); } } public void setTableEnd(DataGrid dataGrid,StringBuffer buffer){ buffer.append("</tr></thead></table>"); } public void setColumn(DataGridColumn column,StringBuffer buffer){ buffer.append("<th "); buffer.append("data-options=\""); if(ToolString.isNotEmpty(column.getField())){ buffer.append("field:'"+column.getField()+"'"); } if(ToolString.isNotEmpty(column.getAlign())){ buffer.append(",align:'"+column.getAlign()+"'"); } if(column.getHidden()){ buffer.append(",hidden:'"+column.getHidden()+"'"); } if("opt".equals(column.getField())){ buffer.append(",formatter:formatter_opt_"+tableName+""); }else{ if(ToolString.isNotEmpty(column.getFormatter())){ buffer.append(",formatter:"+column.getFormatter()+""); } if(ToolString.isNotEmpty(column.getDict())||ToolString.isNotEmpty(column.getReplace())){ buffer.append(",formatter:"+column.getField()+"Replace"); } if(column.getImage()){ buffer.append(",formatter:"+column.getField()+"Img"); } } if(ToolString.isNotEmpty(column.getWidth())){ buffer.append(",width:"+column.getWidth()+""); } buffer.append("\">"+column.getText()+"</th>"); //值替换 if (ToolString.isNotEmpty(column.getReplace())) { String[] test = column.getReplace().split(","); String text = ""; String value = ""; for (String string : test) { text += string.substring(0, string.indexOf("_")) + ","; value += string.substring(string.indexOf("_") + 1) + ","; } setColumnReplace(column.getField(), text, value); } //数据字典 if (ToolString.isNotEmpty(column.getDict())) { String text = ""; String value = ""; List<TType> typeList = CacheKit.get(Constant.CACHE_NAME_SYSTEM_TYPE, ThreadParamInit.CACHESTART_TYPE + column.getDict()); if (typeList != null && !typeList.isEmpty()) { for (TType type : typeList) { text += type.getName() + ","; value += type.getCode() + ","; } setColumnReplace(column.getField(), text, value); } } //图片列 if(column.getImage()){ columnImgList.add(column); } //查询列 if(column.getQuery()){ columnQueryList.add(column); } } public void setOptColumn(StringBuffer buffer){ TagUtil.setOptColumn(columnOptList, buffer, tableName); } public List<TagNestContext> getColumn(){ HttpServletRequest request = (HttpServletRequest) this.ctx.getGlobal("request"); TagNestContext tnc = (TagNestContext) request.getAttribute("tagContext"); List<TagNestContext> list = tnc.getChildren(); return list; } /** * @Title: searchForm * @Description: 组装搜索方法 * @param @param buffer 设定文件 * @return void 返回类型 * @throws */ public void setSearchForm(StringBuffer buffer,DataGrid dataGrid){ //搜索方法开始 buffer.append("function search_"+tableName+"(){\n"); if(dataGrid.treeTable){ buffer.append("$('#"+tableName+"').treegrid('load',\n"); }else{ buffer.append("$('#"+tableName+"').datagrid('load',\n"); } buffer.append("serializeObject($('#form_"+tableName+"'))\n"); buffer.append(");};"); //清除查询条件、返回初始数据展示状态 if(dataGrid.treeTable){ buffer.append("function clean_"+tableName+"(){$('#"+tableName+"').treegrid('load',{});$(':input','#form_"+tableName+"').not(':button, :submit, :reset') .val('') .removeAttr('checked') .removeAttr('selected');}"); }else{ buffer.append("function clean_"+tableName+"(){$('#"+tableName+"').datagrid('load',{});$(':input','#form_"+tableName+"').not(':button, :submit, :reset') .val('') .removeAttr('checked') .removeAttr('selected');}"); } } public void clearList(){ tableName = null; columnOptList.clear(); columnValueList.clear(); columnImgList.clear(); columnQueryList.clear(); } /** * @Title: 获取图片列方法 * @author:YangLi * @param @param buffer 设定文件 * @return void 返回类型 * @throws */ private void getImgColumn(StringBuffer buffer){ for (DataGridColumn column : columnImgList) { buffer.append("function "+column.getField()+"Img(value,rec,index){"); if(ToolString.isEmpty(column.getImageWidth())){ buffer.append(" if(value == \"\" || value == null){return '<img width=\"50px\" border=\"0\" src=\"/common/plug-in/main/images/zanwu.jpg\"/>'}"); buffer.append(" return '<img width=\"50px\" border=\"0\" src=\"'+value+'\"/>'}"); }else{ buffer.append(" if(value == \"\" || value == null){return '<img width=\""+column.getImageWidth()+"\"px border=\"0\" src=\"/common/plug-in/main/images/zanwu.jpg\"/>'}"); buffer.append(" return '<img width=\""+column.getImageWidth()+"\"px border=\"0\" src=\"'+value+'\"/>'}"); } } } /** * * <b>Summary: </b> setColumn(设置字段替换值) * * @param name * @param text * @param value */ public void setColumnReplace(String name, String text, String value) { DataGridColumnReplace columnValue = new DataGridColumnReplace(); columnValue.setName(name); columnValue.setText(text); columnValue.setValue(value); columnValueList.add(columnValue); } protected void setReplace(StringBuffer buffer){ // 值替換 if (columnValueList.size() > 0) { for (DataGridColumnReplace columnValue : columnValueList) { String testString = ""; String[] value = columnValue.getValue().split(","); String[] text = columnValue.getText().split(","); buffer.append("function "+columnValue.getName()+"Replace(value,rec,index){"); for (int j = 0; j < value.length; j++) { if(value[j] == "' '" || "' '".equals(value[j])){ value[j] = ""; } testString += "if(value=='" + value[j]+ "'){return \'" + text[j] + "\'}"; } buffer.append(testString); buffer.append("else{return value}"); buffer.append("}"); } } } }
第四步编写标签工具类TagUtil
/** * * @ClassName : TagUtil * 标签工具类 * @author : YangLi * @date : 2015年6月3日 下午2:30:29 * */ @SuppressWarnings({ "rawtypes", "unchecked" ,"static-access"}) public class TagUtil { /** * @Title: setOptColumn * @Description: 设置操作列 * @param @param listOpt * @param @param buffer * @param @param tableName 设定文件 * @return void 返回类型 * @throws */ public static void setOptColumn(List<DataGridOpt> listOpt,StringBuffer buffer,String tableName){ if(listOpt == null || listOpt.size() == 0) return; buffer.append("function formatter_opt_"+tableName+"(val,row,index){ "); buffer.append("var href='';"); String url = null; for (DataGridOpt opt : listOpt) { url = opt.getUrl(); MessageFormat formatter = new MessageFormat(""); if (opt.getValue() != null) { String[] testvalue = opt.getValue().split(","); List value = new ArrayList<Object>(); for (String test : testvalue) { value.add("\"+row." + test + " +\""); } url = formatter.format(url, value.toArray()); } if (url != null && opt.getValue() == null) { url = formatUrl(url); } String exp = opt.getExp();// 判断显示表达式 if (ToolString.isNotEmpty(exp)) { String[] ShowbyFields = exp.split("&&"); for (String ShowbyField : ShowbyFields) { int beginIndex = ShowbyField.indexOf("#"); int endIndex = ShowbyField.lastIndexOf("#"); String exptype = ShowbyField.substring(beginIndex + 1, endIndex);// 表达式类型 String field = ShowbyField.substring(0, beginIndex);// 判断显示依据字段 String[] values = ShowbyField.substring(endIndex + 1, ShowbyField.length()).split(",");// 传入字段值 String value = ""; for (int i = 0; i < values.length; i++) { value += "'" + "" + values[i] + "" + "'"; if (i < values.length - 1) { value += ","; } } if ("eq".equals(exptype)) { buffer.append("if($.inArray(\"\"+row." + field + ",[" + value + "])>=0){"); } if ("ne".equals(exptype)) { buffer.append("if($.inArray(\"\"+row." + field + ",[" + value + "])<0){"); } if ("empty".equals(exptype) && value.equals("'true'")) { buffer.append("if(\"\"+row." + field + "==''){"); } if ("empty".equals(exptype) && value.equals("'false'")) { buffer.append("if(\"\"+row." + field + "!=''){"); } } } if (OptTypeDirection.del.toString().equals(opt.getType())) { buffer.append("href+=\"<button class='btn btn-sm btn-outline "); buffer.append(opt.getButtonClz()+"\'"); buffer.append(" onclick=delObj(\'" + url+ "\',\'" + tableName + "\')"); buffer.append(" type=\'button\'>"); buffer.append("<i class=\'fa "+opt.getIconClz()+"\'></i>"); buffer.append(" "+opt.getText()); buffer.append("</button> \";"); } if (OptTypeDirection.fun.toString().equals(opt.getType())) { String name = TagUtil.getFunction(opt.getFunname()); String parmars = TagUtil.getFunParams(opt.getFunname()); buffer.append("href+=\"<button class='btn btn-sm btn-outline "); buffer.append(opt.getButtonClz()+"\'"); buffer.append(" onclick="+name+"("+parmars+")"); buffer.append(" type=\'button\'>"); buffer.append("<i class=\'fa "+opt.getIconClz()+"\'></i>"); buffer.append(" "+opt.getText()); buffer.append("</button> \";"); } if (OptTypeDirection.openwin.toString().equals(opt.getType())) { buffer.append("href+=\"<button class='btn btn-sm btn-outline "); buffer.append(opt.getButtonClz()+"\'"); buffer.append(" onclick=addPage(\'" + url+ "\',\'" + opt.getText() + "\')"); buffer.append(" type=\'button\'>"); buffer.append("<i class=\'fa "+opt.getIconClz()+"\'></i>"); buffer.append(" "+opt.getText()); buffer.append("</button> \";"); } if (ToolString.isNotEmpty(exp)) { for (int i = 0; i < exp.split("&&").length; i++) { buffer.append("}"); } } } buffer.append("return href;}"); } /** * 获取自定义函数名 * * @param functionname * @return */ public static String getFunction(String functionname) { int index = functionname.indexOf("("); if (index == -1) { return functionname; } else { return functionname.substring(0, functionname.indexOf("(")); } } /** * 获取自定义函数的参数 * * @param functionname * @return */ public static String getFunParams(String functionname) { int index = functionname.indexOf("("); String param=""; if (index != -1) { String testparam = functionname.substring(functionname.indexOf("(")+1, functionname.length() - 1); if(ToolString.isNotEmpty(testparam)) { String[] params=testparam.split(","); for (String string : params) { //是数字表示,手动传入状态 if(ToolString.isNumeric(string)){ param+= string.replaceAll("_", "")+","; }else{ param+="'\"+row."+ string + "+\"',"; } } } } param+="'\"+index+\"'";//传出行索引号参数 return param; } /** * 格式化URL * * @return */ private static String formatUrl(String url) { String parurlvalue = ""; if (url.indexOf("?") >= 0) { String beforeurl = url.substring(0, url.indexOf("?"));// 截取请求地址 String parurl = url.substring(url.indexOf("?") + 1, url.length());// 截取参数 String[] pras = parurl.split("&"); List value = new ArrayList<Object>(); int j = 0; for (int i = 0; i < pras.length; i++) { if (pras[i].indexOf("{") >= 0 || pras[i].indexOf("#") >= 0) { String field = pras[i].substring(pras[i].indexOf("{") + 1, pras[i].lastIndexOf("}")); if(i == 0){ parurlvalue += "?"+ pras[i].replace("{" + field + "}", "{" + j + "}"); }else{ parurlvalue += "&"+ pras[i].replace("{" + field + "}", "{" + j + "}"); } value.add("\"+row." + field + " +\""); j++; } else { parurlvalue += "" + pras[i]; } } url = MessageFormat.format(beforeurl + parurlvalue, value.toArray()); } return url; } }
相关推荐
赠送jar包:jfinal-mail-plugin-3.0.jar; 赠送原API文档:jfinal-mail-plugin-3.0-javadoc.jar; 赠送源代码:jfinal-mail-plugin-3.0-sources.jar; 赠送Maven依赖信息文件:jfinal-mail-plugin-3.0.pom; 包含...
《深入剖析JFinal框架:基于jfinal-2.1-src.zip源码的探索》 JFinal,作为一款由中国开发者编写的轻量级Java Web框架,以其简洁高效的特性赢得了广大开发者的喜爱。它提供了丰富的功能,使得Web应用开发变得更加...
"jfinal-weixin-1.2-bin-with-src.jar" 提供了微信插件的示例代码,方便开发者学习如何集成和使用。"jfinal-1.8-manual.pdf" 则是JFinal 1.8的手册,虽然版本略旧,但仍能提供很多基础和进阶的开发指导。"jfinal-...
赠送jar包:jfinal-mail-plugin-3.0.jar; 赠送原API文档:jfinal-mail-plugin-3.0-javadoc.jar; 赠送源代码:jfinal-mail-plugin-3.0-sources.jar; 赠送Maven依赖信息文件:jfinal-mail-plugin-3.0.pom; 包含...
该项目是一款基于jfinal、easyUI和activiti框架构建的企业级协同平台设计源码。该平台集成了1705个PNG图片、921个GIF动画、404个JavaScript脚本、333个CSS样式、210个Java源代码、153个HTML页面、101个JAR库文件、48...
赠送jar包:JFinal-ueditor-0.0.3.jar; 赠送原API文档:JFinal-ueditor-0.0.3-javadoc.jar; 赠送源代码:JFinal-ueditor-0.0.3-sources.jar; 赠送Maven依赖信息文件:JFinal-ueditor-0.0.3.pom; 包含翻译后的API...
jfinal-oauth2.0-server jfinal-oauth2.0-server 基于,, 参考 实现了4.节描述的内容。 实现了OAuth 2.0定义了四种授权方式 授权码模式(authorization code): 先获取下次请求token的code,然后在带着code去请求...
赠送jar包:JFinal-ueditor-0.0.3.jar; 赠送原API文档:JFinal-ueditor-0.0.3-javadoc.jar; 赠送源代码:JFinal-ueditor-0.0.3-sources.jar; 赠送Maven依赖信息文件:JFinal-ueditor-0.0.3.pom; 包含翻译后的API...
3. `jfinal-rediscluster-plugin-by-shixiaotian-0.0.1.jar`:这应该是JFinal Redis Cluster插件的jar包,由开发者shixiaotian创建,版本为0.0.1,用于在JFinal项目中支持Redis集群。 4. `readme.txt`:通常这个文件...
jfinal-jfinal-weixin-master.zip 基于maven jfinal 的微信公众号/小程序开发demo
1.使用jfinal-shiro实现数据库级别的权限灵活定制,和freemarker的权限标签 2.使用jfinal-captcha实现验证码 3.使用jfinal-web实现根据ajax请求返回json数据,其他返回默认数据,支持继承JFController使用getModels...
jFinal01-1.0-SNAPSHOT.war
JFinal 是基于 Java 语言的极速 WEB + ORM 开发框架,其核心设计目标是开发迅速、代 码量少、学习简单、功能强大、轻量级、易扩展、Restful。在拥有 Java 语言所有优势的同时 再拥有 ruby、python、php 等动态语言的...
jfinal enjoy-3.3-manual 开发使用手册 3.3版本 官方下载
赠送jar包:jfinal-3.0.jar; 赠送原API文档:jfinal-3.0-javadoc.jar; 赠送源代码:jfinal-3.0-sources.jar; 赠送Maven依赖信息文件:jfinal-3.0.pom; 包含翻译后的API文档:jfinal-3.0-javadoc-API文档-中文...
赠送jar包:jfinal-3.0.jar; 赠送原API文档:jfinal-3.0-javadoc.jar; 赠送源代码:jfinal-3.0-sources.jar; 赠送Maven依赖信息文件:jfinal-3.0.pom; 包含翻译后的API文档:jfinal-3.0-javadoc-API文档-中文...
JFinal集成Shiro插件,实现登录安全,权限控制等。。。。
"jfinal-3.6-all" 这个文件很可能是一个包含 JFinal 3.6 全部依赖的归档文件,可能包括 JFinal 框架的核心库、Jetty 服务器以及其他必要的第三方库。解压后,开发者可以直接将这些 jar 包加入到项目的 classpath 中...
JFinal 是基于 Java 语言的极速 WEB + ORM 框架,其核心设计目标是开发迅速、代码量少、学习简单、功能强大、轻量级、易扩展、Restful。在拥有Java语言所有优势的同时再拥有ruby、python、php等动态语言的
使用JFinal Redis Cluster插件时,首先需要将其引入到项目中,这里我们看到有一个名为 "jfinal-rediscluster-plugin-by-shixiaotian-0.0.1.jar" 的文件,这应该是该插件的可执行版本。通常,开发者会将这个JAR文件...