カスタムラベルの例
4877 ワード
WEB-INF xxx.tld
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN"
"http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd">
<taglib>
<tlibversion>1.0</tlibversion>
<jspversion>1.0</jspversion>
<shortname>tiles</shortname>
<uri>http://jakarta.apache.org/struts/tags-tiles</uri>
<!-- -->
<tag>
<!-- -->
<name>date</name>
<!-- -->
<tagclass>com.clouds.util.tag.DateTag</tagclass>
<!-- , empty-->
<bodycontent>jsp</bodycontent>
<!-- -->
<attribute>
<name>value</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>type</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
<tag>
<!-- -->
<name>delivery</name>
<!-- -->
<tagclass>com.clouds.util.tag.DeliveryTag</tagclass>
<!-- , empty-->
<bodycontent>jsp</bodycontent>
<!-- -->
<attribute>
<name>value</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
<tag>
<!-- -->
<name>product</name>
<!-- -->
<tagclass>com.clouds.util.tag.ProductsTag</tagclass>
<!-- , empty-->
<bodycontent>jsp</bodycontent>
<!-- -->
<attribute>
<name>value</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
</taglib>
新規対応クラス:/**
* @Title: DateTag.java
* @Package com.clouds.util
* @Description: TODO( )
* @author
* @date 2012-9-11 05:20:46
* @version V1.0
*/
package com.clouds.util.tag;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;
/**
* @ClassName: DateTag
* @Description: TODO( )
* @author
* @date 2012-9-11 05:20:46
*
*/
public class DateTag extends TagSupport {
private static final long serialVersionUID = 6464168398214506236L;
private String value;
private String type;
@Override
public int doStartTag() throws JspException {
String vv = ""+value;
if (value != null && !"".equals(value)) {
Long a = Long.valueOf(value);
Long aa = (Long) a * 1000;
Date b = new Date(aa);
if (type == null || "".equals(type)) {
type = "yyyy-MM-dd HH:MM:ss";
}
SimpleDateFormat sdf= new SimpleDateFormat(type);
String date = sdf.format(b);
try {
pageContext.getOut().write(date+"");
} catch (IOException e) {
e.printStackTrace();
}
}
return super.doStartTag();
}
public static void main(String[] args) throws JspException {
DateTag tag = new DateTag();
tag.doStartTag();
}
public void setValue(String value) {
this.value = value;
}
/**
* @return type
*/
public String getType() {
return type;
}
/**
* @param type
*/
public void setType(String type) {
this.type = type;
}
}
:
<common:data value="" type=""></common:data>