📄 selecttag.java
字号:
package com.core.taglib;
import java.util.*;
import org.apache.commons.logging.*;
import com.opensymphony.webwork.views.jsp.*;
import com.core.taglib.components.*;
public class SelectTag extends BaseTag {
private static Log log = LogFactory.getLog(SelectTag.class);
protected boolean emptyOption = false;
protected boolean multiple = false;
protected String size;
protected String list;
String cachename = "";
public SelectTag() {
}
public int doStartTag() throws javax.servlet.jsp.JspException {
return SKIP_BODY;
}
public int doEndTag() throws javax.servlet.jsp.JspException {
try {
pageContext.getOut().print(getHtmlStr());
} catch (Exception e) {
throw new javax.servlet.jsp.JspException(e);
}
return EVAL_BODY_INCLUDE;
}
//得到独特属性的字符串
public String getSelfStr() {
StringBuffer bufSelf = new StringBuffer();
if (multiple) {
bufSelf.append(" multiple ");
}
if (isEmptyOption()) {
bufSelf.append(" emptyOption=\"true\" ");
}
if (getSize() != null && !getSize().equals("")) {
bufSelf.append(" size=\"" + getSize() + "\"");
}
if (getValue() != null && !getValue().equals("")) {
bufSelf.append(" value=\"" + getValue() + "\"");
}
return bufSelf.toString();
}
/**
* 下拉框和录入框合二为一:
* 1、如果缓存中没有就显示输入框。
* 2、如果缓存中有就显示下拉框。
*/
public String getHtmlStr() {
String ret = "";
// 两种情况都相同的部分
String strComm = super.getCommHtml() + this.getSelfStr();
// 检查OgnlValueStack是否有值。
Object stackObject = TagUtils.getStack(this.pageContext).findValue(name);
// if (this.getList() != null && this.getList().equals("sel_bmlist")) { /** 现有部门 */
// this.setList(com.xckj.mdgl.common.cache.DeptCache.getInstance().select_list);
// } else if (this.getList() != null && this.getList().equals("sel_bmlist_all")) { /** 所有部门 */
// this.setList(com.xckj.mdgl.common.cache.DeptCache.getInstance().select_list_all);
// } else if (this.getList() != null && this.getList().equals("sel_bmlist_zf")) { /** 作废部门 */
// this.setList(com.xckj.mdgl.common.cache.DeptCache.getInstance().select_list_zf);
// }
// else if (this.getList() != null && this.getList().equals("select_list_all_bm_gw")) { /** 所有部门岗位 */
// this.setList(com.xckj.mdgl.common.cache.PostCache.getInstance().select_list_all_bm_gw);
// } else if (this.getList() != null && this.getList().equals("select_list_bm_gw")) { /** 现有部门岗位 */
// this.setList(com.xckj.mdgl.common.cache.PostCache.getInstance().select_list_bm_gw);
// } else if (this.getList() != null && this.getList().equals("select_list_zf_bm_gw")) { /** 作废部门岗位 */
// this.setList(com.xckj.mdgl.common.cache.PostCache.getInstance().select_list_zf_bm_gw);
// } else if (this.getList() != null && this.getList().equals("select_gwlist_all")) { /** 所有岗位 */
// this.setList(com.xckj.mdgl.common.cache.PostCache.getInstance().select_list_all);
// } else if(this.getList() != null && this.getList().equals("select_gwlist")){/** 现有岗位 */
// this.setList(com.xckj.mdgl.common.cache.PostCache.getInstance().select_list);
// }else if(this.getList() != null && this.getList().equals("select_gwlist_zf")){/** 作废岗位 */
// this.setList(com.xckj.mdgl.common.cache.PostCache.getInstance().select_list_zf);
// }
// else if (this.getList() != null && this.getList().equals("select_yglist_all")) { /** 所有员工 */
// this.setList(com.xckj.mdgl.common.cache.UserCache.getInstance().select_list_all);
// } else if (this.getList() != null && this.getList().equals("select_yglist")) { /** 现有人 */
// this.setList(com.xckj.mdgl.common.cache.UserCache.getInstance().select_list);
// } else if (this.getList() != null && this.getList().equals("select_yglist_zf")) { /** 作废人 */
// this.setList(com.xckj.mdgl.common.cache.UserCache.getInstance().select_list_zf);
// } else if (this.getList() != null && this.getList().equals("select_list_bm_yg")) { /** 现有部门人 */
// this.setList(com.xckj.mdgl.common.cache.UserCache.getInstance().select_list_bm_yg);
// } else if (this.getList() != null && this.getList().equals("select_list_zf_bm_gw")) { /** 作废部门人 */
// this.setList(com.xckj.mdgl.common.cache.UserCache.getInstance().select_list_zf_bm_yg);
// } else if (this.getList() != null && this.getList().equals("select_list_all_bm_yg")) { /** 所有部门人 */
// this.setList(com.xckj.mdgl.common.cache.UserCache.getInstance().select_list_all_bm_yg);
// }
if (this.getList() != null && !this.getList().equals("")) {
ret = "<select" + strComm + ">";
if (isEmptyOption()) {
ret += "<option value=\"\">--请选择--</option>";
}
String temp = this.getList().substring(this.getList().indexOf("{") + 1, this.getList().indexOf("}"));
String[] listVal = temp.split(",");
for (int i = 0; i < listVal.length; i++) {
if (listVal[i].indexOf(":") != -1) {
String[] keyVal = listVal[i].split(":");
if (null != stackObject) {
ret += "<option value=\"" + keyVal[1] + "\"" +
(keyVal[1].equals(stackObject.toString()) || keyVal[1].equals(getValue()) ? " selected" : "") + ">" + keyVal[0] + "</option>";
} else {
ret += "<option value=\"" + keyVal[1] + "\"" +
(keyVal[1].equals(getValue()) ? " selected" : "") + ">" + keyVal[0] + "</option>";
}
} else {
if (null != stackObject) {
ret += "<option value=\"" + listVal[i] + "\"" +
(listVal[i].equals(stackObject.toString()) || listVal[1].equals(getValue()) ? " selected" : "") + ">" + listVal[i] + "</option>";
} else {
ret += "<option value=\"" + listVal[i] + "\"" +
(listVal[1].equals(getValue()) ? " selected" : "") + ">" + listVal[i] + "</option>";
}
}
}
ret += "</select>";
} else if (null != cachename && !cachename.equals("")) {
String code = "";
if (getValue() == null) {
code = getValue();
}
if (null != stackObject) {
code = stackObject.toString();
}
ret = "<select" + strComm + "> ";
if (isEmptyOption()) {
ret += "<option value=\"\">--请选择--</option>";
}
String strSelectCacheName = name;
if (null != cachename && !cachename.equals("")) {
strSelectCacheName = cachename;
}
// 检查是否有缓存列表。
List selectList = SelcetCache.getInstance().getSelect(strSelectCacheName);
if (selectList != null && selectList.size() > 0) {
for (int i = 0; i < selectList.size(); i++) {
SelectOption option = (SelectOption) selectList.get(i);
ret += "<option value=\"" + option.getValue() + "\" " + (option.getValue().equals(code) ? " selected" : "") + ">" + option.getTitle() + "</option>";
}
}
ret += "</select>";
} else {
ret = "<select" + strComm + "> ";
if (isEmptyOption()) {
ret += "<option value=\"\">--请选择--</option>";
}
}
return ret;
}
public String getCachename() {
return cachename;
}
public boolean isMultiple() {
return multiple;
}
public String getSize() {
return size;
}
public boolean isEmptyOption() {
return emptyOption;
}
public String getList() {
return list;
}
public void setCachename(String cachename) {
this.cachename = cachename;
}
public void setMultiple(boolean multiple) {
this.multiple = multiple;
}
public void setSize(String size) {
this.size = size;
}
public void setEmptyOption(boolean emptyOption) {
this.emptyOption = emptyOption;
}
public void setList(String list) {
this.list = list;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -