📄 editortag.java
字号:
package com.core.taglib;
import java.util.List;
import com.core.taglib.components.SelectOption;
import com.opensymphony.webwork.views.jsp.TagUtils;
import org.apache.commons.logging.LogFactory;
import org.apache.commons.logging.Log;
public class EditorTag extends javax.servlet.jsp.tagext.TagSupport {
private static Log log = LogFactory.getLog(EditorTag.class);
String name = "";
String type = "";
String size = "";
boolean nullable = true;
String charset = "";
String datatype = "";
String namevalue = "";
public EditorTag() {
}
public int doStartTag() throws javax.servlet.jsp.JspException {
return SKIP_BODY;
}
public int doEndTag() throws javax.servlet.jsp.JspException {
try {
String strHtml = getEditor();
pageContext.getOut().print(strHtml);
} catch (Exception e) {
throw new javax.servlet.jsp.JspException(e);
}
return EVAL_BODY_INCLUDE;
}
/**
* 下拉框和录入框合二为一:
* 1、如果缓存中没有就显示输入框。
* 2、如果缓存中有就显示下拉框。
*/
public String getEditor() {
String ret="";
// 两种情况都相同的部分
String strComm=" name='"+name+"' type='"+type+"' size='"+size+"' nullable='"+nullable+"' charset='"+charset+"' datatype='"+datatype+"' namevalue='"+namevalue+"'";
// 检查OgnlValueStack是否有值。
Object stackObject = TagUtils.getStack(this.pageContext).findValue(name);
String code = "";
String strInputValue="";
if (null != stackObject) {
code = stackObject.toString();
strInputValue = "value='"+code+"'";
log.info("在OgnlValueStack找到了" + name + "! 它的值是:" + code);
}
// 检查是否有缓存列表。
List selectList=SelcetCache.getInstance().getSelect(name);
if(null==selectList){//1、如果缓存中没有就显示输入框。
ret="<input "+strComm+strInputValue+">";
}else{//2、如果缓存中有就显示下拉框。
ret="<select"+strComm+">";
ret+="<option value=''>---请选择---</option>";
for(int i=0;i<selectList.size();i++){
SelectOption option=(SelectOption)selectList.get(i);
String isSelect="";
if(option.getValue().equals(code)){
isSelect="selected";
}
ret+="<option value='"+option.getValue()+"' "+isSelect+">"+option.getTitle()+"</option>";
}
ret+="</select>";
}
return ret;
}
public String getCharset() {
return charset;
}
public String getDatatype() {
return datatype;
}
public String getName() {
return name;
}
public String getNamevalue() {
return namevalue;
}
public String getSize() {
return size;
}
public String getType() {
return type;
}
public boolean isNullable() {
return nullable;
}
public void setCharset(String charset) {
this.charset = charset;
}
public void setDatatype(String datatype) {
this.datatype = datatype;
}
public void setName(String name) {
this.name = name;
}
public void setNamevalue(String namevalue) {
this.namevalue = namevalue;
}
public void setSize(String size) {
this.size = size;
}
public void setType(String type) {
this.type = type;
}
public void setNullable(boolean nullable) {
this.nullable = nullable;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -