关注JEECG发展历程 关注最新动态和版本, 记录JEECG成长点滴 更新日志 - 技术支持 - 招聘英才

JEECG最新版本下载 JEECG智能开发平台 - 显著提高开发效率 常见问题 - 入门视频 - 参与开源团队

商务QQ: 69893005、3102411850 商务热线(5*8小时): 010-64808099 官方邮箱: jeecgos@163.com

查看: 18889|回复: 12

自己写的标签,用作查询使用

[复制链接]
发表于 2013-7-6 18:16:32 | 显示全部楼层 |阅读模式
自己写东西的时候用到的,可能这个字段并没有可以显示,但是要作为查询条件显示到页面上,但是感觉jeecg还木有,就自己写了个,
其实很简单,就是这个这个标签加入到jeecg自带的标签中就可以了
下面是代码
  1. package org.jeecgframework.tag.core.easyui;

  2. import javax.servlet.jsp.JspTagException;
  3. import javax.servlet.jsp.tagext.Tag;
  4. import javax.servlet.jsp.tagext.TagSupport;

  5. /**
  6. *
  7. * 类描述:列表查询操作项标签
  8. *
  9. * @author: jueyue
  10. * @date: 2013年6月17日21:42:41
  11. * @version 1.0
  12. */
  13. public class DataGridQurOptTag extends TagSupport {
  14.         /**
  15.          *
  16.          */
  17.         private static final long serialVersionUID = 1L;
  18.         private String title;
  19.         private String field;
  20.         private String replace;
  21.         private String queryMode = "single";
  22.         public int doStartTag() throws JspTagException {
  23.                 return EVAL_PAGE;
  24.         }
  25.         public int doEndTag() throws JspTagException {
  26.                 Tag t = findAncestorWithClass(this, DataGridTag.class);
  27.                 DataGridTag parent = (DataGridTag) t;
  28.                 parent.setQurUrl(title,field,replace,queryMode);
  29.                 return EVAL_PAGE;
  30.         }
  31.         public void setTitle(String title) {
  32.                 this.title = title;
  33.         }
  34.         public void setReplace(String replace) {
  35.                 this.replace = replace;
  36.         }
  37.         public void setField(String field) {
  38.                 this.field = field;
  39.         }
  40.         public void setQueryMode(String queryMode) {
  41.                 this.queryMode = queryMode;
  42.         }
  43.         
  44.         
  45. }
复制代码
这里面的parent是这个类  org.jeecgframework.tag.core.easyui.DataGridTag
加入这个方法
  1. /**
  2.          * 设置查询框
  3.          * @param title
  4.          * @param field
  5.          * @param message
  6.          * @param exp
  7.          * @param replace
  8.          * @param queryMode
  9.          */
  10.         public void setQurUrl(String title,String field,String replace, String queryMode) {
  11.                 DateGridColumn dateGridUrl = new DateGridColumn();
  12.                 dateGridUrl.setTitle(title);
  13.                 dateGridUrl.setField(field);
  14.                 dateGridUrl.setReplace(replace);
  15.                 dateGridUrl.setQueryMode(queryMode);
  16.                 queryList.add(dateGridUrl);
  17.         }
复制代码
之后在这个类的方法end里面加入写字段

  1.                         if(hasQueryColum(columnList)){
  2.                                 
  3.                                 sb.append("<div name="searchColums">");
  4.                                 //如果表单是组合查询
  5.                                 if("group".equals(getQueryMode())){
  6.                                         for (DateGridColumn col : columnList) {
  7.                                                 if (col.isQuery()) {
  8.                                                         sb.append(createQuerySpan(col));
  9.                                                 }
  10.                                         }
  11.                                         for (DateGridColumn col : queryList) {
  12.                                                 sb.append(createQuerySpan(col));
  13.                                         }
  14.                                        
  15.                                        
  16.                                 }
  17.                                 sb.append("</div>");
  18.                         }
复制代码
之后再easyui加入这个tag就可以了
  1.   <name>dgQurOpt</name>
  2.   <tag-class>org.jeecgframework.tag.core.easyui.DataGridQurOptTag</tag-class>
  3.   <body-content>jsp</body-content>
  4.   <description>列表查询选项</description>
  5.   <attribute>
  6.    <name>title</name>
  7.    <required>true</required>
  8.    <rtexprvalue>true</rtexprvalue>
  9.    <description>查询标题</description>
  10.   </attribute>
  11.   <attribute>
  12.    <name>field</name>
  13.    <required>true</required>
  14.    <rtexprvalue>true</rtexprvalue>
  15.    <description>查询字段</description>
  16.   </attribute>
  17.   <attribute>
  18.    <name>replace</name>
  19.    <rtexprvalue>true</rtexprvalue>
  20.    <description>替换</description>
  21.   </attribute>
  22.   <attribute>
  23.    <name>queryMode</name>
  24.    <rtexprvalue>true</rtexprvalue>
  25.    <description>查询方式</description>
  26.   </attribute>
  27. </tag>
复制代码
最后在jsp中这样写就可以使用了,哇咔咔,是不是很简单啊
<t:dgQurOpt field="productName" title="产品名称"></t:dgQurOpt>
大家快来丰富jeecg吧,



发表于 2013-7-6 19:11:34 | 显示全部楼层
牛啊!支持一个!
发表于 2013-7-8 02:30:11 | 显示全部楼层
无标题2.png
按照上面的方法,我在end中加入代码的时候报错误,createQuerySpan(col)方法和queryList变量都不存在。
发表于 2013-7-8 02:31:36 | 显示全部楼层
setQurUrl方法中,也报queryList变量不存在的错误:queryList cannot be resolved
发表于 2013-7-8 11:27:29 | 显示全部楼层
me too me too me too
发表于 2013-7-8 13:02:02 | 显示全部楼层
额 这个可能是在最新的代码上写的 大家要等新版本发布了
 楼主| 发表于 2013-7-9 23:59:59 | 显示全部楼层
chubing07 发表于 2013-7-8 02:30
按照上面的方法,我在end中加入代码的时候报错误,createQuerySpan(col)方法和queryList变量都不存在。
...

那个queryList要自己定义下
 楼主| 发表于 2013-7-10 00:01:53 | 显示全部楼层
protected List<DateGridColumn> queryList = new ArrayList<DateGridColumn>();// 查询列表
/**
         * 创建查询面板
         * @param col
         * @return
         */
        private String createQuerySpan(DateGridColumn col) {
                StringBuilder sb = new StringBuilder();
                sb.append("<span style=\"display:-moz-inline-box;display:inline-block;\">");
                sb.append("<span style=\"display:-moz-inline-box;display:inline-block;width: 80px;text-align:right;\">"+col.getTitle()+":</span>");
                if("single".equals(col.getQueryMode())){
                        //update-begin--Author:zhaojunfu  Date:20130510 for:【TASK #95】生成select选择框
                        if(!StringUtil.isEmpty(col.getReplace())){
                                sb.append("<select name=\""+col.getField()+"\" WIDTH=\"100\" style=\"width: 104px\"> ");
                                sb.append("<option value =\"\" >---请选择---</option>");
                                String[] test = col.getReplace().split(",");
                                String text = "";
                                String value = "";
                                for (String string : test) {
                                        text = string.split("_")[0];
                                        value =string.split("_")[1];
                                        sb.append("<option value =\""+value+"\">"+text+"</option>");
                                }
                                sb.append("</select>");
                        }else{
                                sb.append("<input type=\"text\" name=\""+col.getField()+"\"  style=\"width: 100px\"/>");
                        }
                }else if("group".equals(col.getQueryMode())){
                        sb.append("<input type=\"text\" name=\""+col.getField()+"_begin\"  style=\"width: 94px\"/>");
                        sb.append("<span style=\"display:-moz-inline-box;display:inline-block;width: 8px;text-align:right;\">~</span>");
                        sb.append("<input type=\"text\" name=\""+col.getField()+"_end\"  style=\"width: 94px\"/>");
                }
                sb.append("</span>");
                return sb.toString();
        }
上面少加的两个方法
发表于 2013-7-15 17:19:14 | 显示全部楼层
没有效果图吗  、 弄一个效果图上来看看。
发表于 2013-7-23 22:52:05 | 显示全部楼层
看了楼主的代码,有个隐性bug。(要嘛有漏贴的代码。)
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表