📄 screenoptionlabeltag.java
字号:
/*
* Created on 2005/12/5
*/
package com.leeman.common.web.ui.tags;
import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.tagext.TagSupport;
import org.apache.commons.beanutils.PropertyUtils;
import com.leeman.common.web.ui.ScreenOption;
/**
* @author Dennis
*/
public class ScreenOptionLabelTag extends TagSupport{
private String listId = null;
private String name = null;
private String valueId = null;
private String value = null;
private String property = null;
public int doEndTag() throws javax.servlet.jsp.JspException{
try {
HttpServletRequest request =(HttpServletRequest)pageContext.getRequest();
Object formBean = request.getAttribute(name);
ArrayList list = (ArrayList)PropertyUtils.getSimpleProperty(formBean, listId);
String optionValue = null;
if (valueId != null && value != null){
throw new Exception("either valueId and value is allowed.");
}
if (valueId != null){
if (property != null){
Object pageObj = pageContext.getAttribute(valueId);
optionValue = (String)PropertyUtils.getSimpleProperty(pageObj, property);
}
else
{
int first = valueId.indexOf("(");
int second = valueId.indexOf(")");
if (first > 0 && second > first){
optionValue = (String)PropertyUtils.getMappedProperty(formBean, valueId);
}
else{
optionValue = (String)PropertyUtils.getSimpleProperty(formBean, valueId);
}
}
}
else{
optionValue = value;
}
int index = -1;
for (int i=0; i <list.size(); i++)
{
ScreenOption so = (ScreenOption)list.get(i);
if (so.getValue() != null){
if (so.getValue().equals(optionValue))
{
index = i;
break;
}
}
}
if (index >= 0)
{
ScreenOption opt = (ScreenOption)list.get(index);
String label = opt.getLabel();
if (label != null){
pageContext.getOut().print(label);
}
}
} catch (Exception e)
{
throw new javax.servlet.jsp.JspException("Error processing ScreenOptionLabelTag.doEndTag(): " + e.toString());
}
return EVAL_PAGE;
}
/**
* @return
*/
public String getListId() {
return listId;
}
/**
* @return
*/
public String getValueId() {
return valueId;
}
/**
* @param string
*/
public void setListId(String string) {
listId = string;
}
/**
* @param string
*/
public void setValueId(String string) {
valueId = string;
}
/**
* @return
*/
public String getValue() {
return value;
}
/**
* @param string
*/
public void setValue(String string) {
value = string;
}
/**
* @return
*/
public String getName() {
return name;
}
/**
* @param string
*/
public void setName(String string) {
name = string;
}
/**
* @return
*/
public String getProperty() {
return property;
}
/**
* @param string
*/
public void setProperty(String string) {
property = string;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -