カスタムタグ
org.apache.struts.taglib.bean.TagSupportクラスを継承したクラスを
作成
public final class ExWriteTag extends WriteTag { // 新規プロパティ追加 protected boolean hoge = false; /** * メソッドをオーバーライド * 任意で処理追加 */ public int doStartTag() throws JspException { // Look up the requested bean (if necessary) if (ignore) { if (TagUtils.getInstance().lookup(pageContext, name, scope) == null) { return (SKIP_BODY); // Nothing to output } } // Look up the requested property value Object value = TagUtils.getInstance().lookup(pageContext, name, property, scope); if (value == null) { return (SKIP_BODY); // Nothing to output } if (hoge) { //なにがしの処理を追記 } // Convert value to the String with some formatting String output = formatValue(value); // Print this property value to our output writer, suitably filtered if (filter) { TagUtils.getInstance().write(pageContext, TagUtils.getInstance().filter(output)); } else { TagUtils.getInstance().write(pageContext, output); } // Continue processing this page return (SKIP_BODY); } }
タグクラスの置き換え
TLDファイルを修正
<!--<tagclass>org.apache.struts.taglib.bean.WriteTag</tagclass>--> <tagclass>ExWriteTag</tagclass> ---省略 <attribute> <name>hoge</name> <required>false</required> <rtexprvalue>false</rtexprvalue> </attribute>