WEB-INF/tlds/app.tld中
定义一个文件。
"http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">
在com.ct.framework.tag中有SelectTag.java
public class SelectTag extends TagSupport{
private final Log logger = LogFactory.getLog(this.getClass());
private String codeType;
private String language;
private String id;//标签id
private String name;//下拉列表名字
private String cssClass;//下拉列表样式
private String style;//风格
private String selectedValue;//已选中的值
private Boolean multiple;//是否可以多选
private Boolean withAll;//是否显示全部
private Boolean withBlack;//是否显示空白
private String codition;//父级列表(筛选条件)
private String onchange;//onchange事件
public int doStartTag() throws JspException{
if(language == null){
language = "C";
}
HttpSession httpSession = this.pageContext.getSession();
StringBuffer resultBuffer = new StringBuffer();
ConditionVo conditionVo = new ConditionVo();
JspWriter jspWriter = pageContext.getOut();
CodeCodeService codeCodeService =
(CodeCodeService)ServiceFactory.getService("codeCodeService");
List
conditionVp.setSearchCondition(condition);
try{
//这步用type查询出类型下的code集合对象
codeCodeList = codeCodeService.listCodeSelect(codeType,conditionVo,httpSession);
}catch(Exception ex){
...
}
//标签的处理
resultBuffer.append("");
try{
logger.debug("SelectTag标签:" + resultBuffer.toString());
jspWriter.print(resultBuffer.toString());
}catch(Exception ex){
...
}
return EVAL_BODY_INCLUDE;
}
public int doEndTag()throws Exception{
this.codeType="";
this.language="";
this.id="";
this.name="";
this.cssClass="";
this.selectedValue="";
this.multiplie=false;
this.withAll=false;
this.withBlack=false;
this.condition="";
this.onchange="";
return EVAL_PAGE;
}
setter getter方法
}
Spring注入Service实例工厂
public class ServiceFactory{
private static WebApplicationContext context;
private ServiceFactory(){}
public static void initServiceFactory(ServletContext servletContext){
context = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
}
public static Object getService(String serviceName){
return context.getBean(serviceName);
}
}