Professional Documents
Culture Documents
Keyton Weissinger
Key Focus, Inc.
keytonw@mindspring.com
27 March 2001
O’Reilly Conference on Enterprise Java
Santa Clara, CA
Agenda, Part I
• Tags? Actions? Huh?
• Tag Interface
• Tag Attributes
• Tags and Scripting Variables
• BREAK
A brief introduction to
custom tags.
<log:logMessage categoryName="testCat"
priority="fatal">
The body contents…
</log:logMessage>
<log:logMessage categoryName="testCat"
priority="fatal" message="test"/>
<attribute>
<name>message</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<log:category id=“myCat”/>
<%
myCat.debug(“Hello!”);
%>
JSP Custom Tags 41
Introduction of Scripting Variables
To have your tag introduce a scripting
variable, you must perform the
following steps:
• Somewhere in your tag handler class
you must add your variable to one of the
JSP scopes.
• Create a TagExtraInfo class for your
tag handler class and reference it in
your TLD.
JSP Custom Tags 42
Creating a Scripting Variable
<log:category id=“myCat”/>
From TagSupport base class:
void setId(String id) {
this.id = id;
}
From your tag’s doStartTag() method:
Category rootCat =
Category.getRoot();
pageContext.setAttribute(id,
rootCat, Page.APPLICATION_SCOPE);
JSP Custom Tags 43
TagExtraInfo Class
public class CategoryTagExtraInfo extends
TagExtraInfo {
public VariableInfo[]
getVariableInfo(TagData data) {
return new VariableInfo[] {
new VariableInfo(
data.getAttributeString("id"),
"org.apache.log4j.Category",
true,
VariableInfo.AT_END)
};
}
}
doEndTag()
<teiclass>
com.foo.CategoryTagExtraInfo
</teiclass>
Scripting Variable
Demo
15 minutes.
<%@taglib%>
out = JspWriter (JSP)
<tag1> out = BodyContent (tag1)
<tag2> out = BodyContent (tag2)
...
</tag2>
</tag1> out = BodyContent (tag1)
out = JspWriter (JSP)
<%@taglib%>
out = JspWriter (JSP)
<tag1> out = BodyContent (tag1)
<tag2> out = BodyContent (tag2)
</tag2>
</tag1> out = BodyContent (tag1)
out = JspWriter (JSP)
JSP Implementation
Class Demo
WEB-INF/
lib/
logtags.jar
Deployment Demo
Questions?