📄 radiotag.java
字号:
package com.core.taglib;
import org.apache.commons.logging.*;
import com.opensymphony.webwork.views.jsp.*;
public class RadioTag extends BaseTag {
private static Log log = LogFactory.getLog(RadioTag.class);
private String checked;
private String list = "";
public RadioTag() {
}
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();
return bufSelf.toString();
}
//得到最终的字符串
public String getHtmlStr() {
String ret = "";
// step1:处理直接输出的普通属性。
String strComm = super.getCommHtml();
// log.info("普通属性的字符串是:"+strComm);
// 检查OgnlValueStack中的值。
Object stackObject = TagUtils.getStack(this.pageContext).findValue(name);
if (this.getList() != null && !this.getList().equals("")) {
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 += "<input type=\"radio\" " + strComm + " value=\"" + keyVal[1] + "\"" +
(keyVal[1].equals(stackObject.toString()) || keyVal[1].equals(getValue()) ? " checked" : "") + "> " + keyVal[0] + " ";
} else {
ret += "<input type=\"radio\" " + strComm + " value=\"" + keyVal[1] + "\"" +
(keyVal[1].equals(getValue()) ? " checked" : "") + "> " + keyVal[0] + " ";
}
}
else{
if (null != stackObject) {
ret += "<input type=\"radio\" " + strComm + " value=\"" + listVal[i] + "\"" +
(listVal[i].equals(stackObject.toString()) || listVal[i].equals(getValue()) ? " checked" : "") + "> " + listVal[i] + " ";
} else {
ret += "<input type=\"radio\" " + strComm + " value=\"" + listVal[i] + "\"" +
(listVal[i].equals(getValue()) ? " checked" : "") + "> " + listVal[i] + " ";
}
}
}
}
else{
if (null != stackObject) {
ret = "<input type=\"radio\" " + strComm + (getValue() == null || getValue().equals("")?"":" value=\"" + super.getValue() + "\"") +
(super.getValue().equals(stackObject.toString()) ? " checked" : "") + "> ";
} else {
ret = "<input type=\"radio\" " + strComm + (getValue() == null || getValue().equals("")?"":" value=\"" + super.getValue() + "\"") + (getChecked() != null?" checked":"") + "> ";
}
}
return ret;
}
public String getList() {
return list;
}
public String getChecked() {
return checked;
}
public void setList(String list) {
this.list = list;
}
public void setChecked(String checked) {
this.checked = checked;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -