taglib:
<tag>
<description>This is a sample tag</description>
<name>formatDate</name>
<tag-class>jp.go.web.tag.FormatTag</tag-class>
<body-content>empty</body-content>
<attribute>
<description>This is a sample attribute</description>
<name>format</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>(ELを使う場合trueを設定する)
<type>jp.go.sample.FormatPattern</type>
</attribute>
</tag>
ENUMクラス:
public enum FormatPattern{
yyyymmdd("YYYY/MM/DD"), yymmdd("YY/MM/DD");
private final String name;
DataformatEnum(String name) {
this.name = name;
}
public String getName() {
return name;
}
};
FormatTagタグクラス:
private FormatPattern format;
public FormatPattern getFormat() {
return format;
}
public void setFormat(FormatPattern format) {
this.format = format;
}
jsp:
<a:formatDate path="id" format="yyyymmdd">
上記とおり、formatDate Tagにはjspで設定したformat属性”yyyymmdd”を取得できます。
format.getName()で"YYYY/MM/DD"を取得できます。
jspでFormatPattern以外の値を設定すると、エラーとなります。