自己写的标签,用作查询使用
自己写东西的时候用到的,可能这个字段并没有可以显示,但是要作为查询条件显示到页面上,但是感觉jeecg还木有,就自己写了个,其实很简单,就是这个这个标签加入到jeecg自带的标签中就可以了
下面是代码package org.jeecgframework.tag.core.easyui;
import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.tagext.Tag;
import javax.servlet.jsp.tagext.TagSupport;
/**
*
* 类描述:列表查询操作项标签
*
* @author: jueyue
* @date: 2013年6月17日21:42:41
* @version 1.0
*/
public class DataGridQurOptTag extends TagSupport {
/**
*
*/
private static final long serialVersionUID = 1L;
private String title;
private String field;
private String replace;
private String queryMode = "single";
public int doStartTag() throws JspTagException {
return EVAL_PAGE;
}
public int doEndTag() throws JspTagException {
Tag t = findAncestorWithClass(this, DataGridTag.class);
DataGridTag parent = (DataGridTag) t;
parent.setQurUrl(title,field,replace,queryMode);
return EVAL_PAGE;
}
public void setTitle(String title) {
this.title = title;
}
public void setReplace(String replace) {
this.replace = replace;
}
public void setField(String field) {
this.field = field;
}
public void setQueryMode(String queryMode) {
this.queryMode = queryMode;
}
}
这里面的parent是这个类org.jeecgframework.tag.core.easyui.DataGridTag
加入这个方法 /**
* 设置查询框
* @param title
* @param field
* @param message
* @param exp
* @param replace
* @param queryMode
*/
public void setQurUrl(String title,String field,String replace, String queryMode) {
DateGridColumn dateGridUrl = new DateGridColumn();
dateGridUrl.setTitle(title);
dateGridUrl.setField(field);
dateGridUrl.setReplace(replace);
dateGridUrl.setQueryMode(queryMode);
queryList.add(dateGridUrl);
}
之后在这个类的方法end里面加入写字段
if(hasQueryColum(columnList)){
sb.append("<div name=\"searchColums\">");
//如果表单是组合查询
if("group".equals(getQueryMode())){
for (DateGridColumn col : columnList) {
if (col.isQuery()) {
sb.append(createQuerySpan(col));
}
}
for (DateGridColumn col : queryList) {
sb.append(createQuerySpan(col));
}
}
sb.append("</div>");
}之后再easyui加入这个tag就可以了<name>dgQurOpt</name>
<tag-class>org.jeecgframework.tag.core.easyui.DataGridQurOptTag</tag-class>
<body-content>jsp</body-content>
<description>列表查询选项</description>
<attribute>
<name>title</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
<description>查询标题</description>
</attribute>
<attribute>
<name>field</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
<description>查询字段</description>
</attribute>
<attribute>
<name>replace</name>
<rtexprvalue>true</rtexprvalue>
<description>替换</description>
</attribute>
<attribute>
<name>queryMode</name>
<rtexprvalue>true</rtexprvalue>
<description>查询方式</description>
</attribute>
</tag>最后在jsp中这样写就可以使用了,哇咔咔,是不是很简单啊
<t:dgQurOpt field="productName" title="产品名称"></t:dgQurOpt>
大家快来丰富jeecg吧,
牛啊!支持一个!:lol
按照上面的方法,我在end中加入代码的时候报错误,createQuerySpan(col)方法和queryList变量都不存在。
setQurUrl方法中,也报queryList变量不存在的错误:queryList cannot be resolved me too me too me too 额 这个可能是在最新的代码上写的 大家要等新版本发布了 chubing07 发表于 2013-7-8 02:30 static/image/common/back.gif
按照上面的方法,我在end中加入代码的时候报错误,createQuerySpan(col)方法和queryList变量都不存在。
...
那个queryList要自己定义下 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:zhaojunfuDate: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("_");
value =string.split("_");
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();
}
上面少加的两个方法 没有效果图吗、 弄一个效果图上来看看。 看了楼主的代码,有个隐性bug。(要嘛有漏贴的代码。)
页:
[1]
2