0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

springframework taglibを拡張する場合、taglibにenum型利用方法

0
Last updated at Posted at 2019-02-01

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以外の値を設定すると、エラーとなります。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?