Struts+Hibernate模板开发笔记---自定义标签

 

  

1.自定义标签库(DateTag.tld)

<?xml version="1.0" encoding="GB2312" ?> <!DOCTYPE taglib
PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"
"http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_2.dtd">

<taglib>
<tlibversion>1.0</tlibversion>
<jspversion>1.2</jspversion>
<shortname>Date Tag Library</shortname>
<info>日期录入标签库</info>

<tag>
<name>inputButton</name>
<tagclass>com.company.demo.tags.DateTag</tagclass>
<bodycontent>empty</bodycontent>

<attribute>
<name>name</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>

</attribute>
<attribute>
<name>type</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>

</attribute>
</tag>

</taglib>

2.Tag类(DateTag.java)

package com.company.demo.tags; import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
import javax.servlet.*;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: </p>
* @author 段洪杰
* @version 1.0
* 生成日期录框
*/
public class DateTag extends TagSupport{
String type,name; //类型和参数名
public void setType(String type)throws JspException {
this.type=type;
}
public void setName(String name)throws JspException {
this.name=name;
}
public int doStartTag() throws JspException {
String string,dialogHeight,dialogWidth,size;
if(type=="date") {
dialogHeight="290";
dialogWidth="240";
size="10";
}
else if(type=="datetime") {
dialogHeight="315";
dialogWidth="240";
size="18";
}
else {
throw new JspTagException("类型参数错误,只能选择date或datetime!");
}
string="<SCRIPT language=javascript>"+
"function selectDate"+name+"(oSource){"+
"window.showModalDialog('content/dtpicker.jsp?rn='+Math.random(),oSource,
'dialogHeight:"+dialogHeight+"px; dialogWidth: "+dialogWidth+"px;center: Yes;
help: No; resizable: No;scroll:No;status: No;')"+ "}"+ "</script>"+ "<INPUT readOnly size="+size+" name="+name+ " DataType=/"date/" comparer=/"compareToLastUsedOn/" dateTimeType="+type+">"+ "<IMG src=/"images/select.gif/" width=/"23/" height=/"23/" align=absMiddle"+ " onclick=selectDate"+name+"(document.all(this.sourceIndex-1))> "; try{ JspWriter out=pageContext.getOut(); out.println(string); } catch(Exception ex) { throw new JspTagException("程序调用标签时出错: "+ex.getMessage()); } return SKIP_BODY; } public int doEndTag() throws JspException { return EVAL_PAGE; } }


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值