Professional Java Server Programming J2EE Edition
Chapter 12
public String getCity() {
return city;
}
}
}
The NameTag class will require a simple NameTagExtraInfo class, which should contain no surprises. It
simply publishes variables not published by the enclosing VarHelloBodyTag. Note that these scripting
variables will only be available within the name tag itself, although those published by the enclosing tag will
still be visible:
package tagext;
import javax.servlet.jsp.tagext.*;
// Variable information for the NameTag.
// @author Rod Johnson
public class NameTagExtraInfo extends TagExtraInfo {
// Return an array of variables set by the VarHelloBodyTag.
public VariableInfo[] getVariableInfo(TagData data) {
return new VariableInfo[] {
new VariableInfo("nationality", "java.lang.String", true,
VariableInfo.NESTED),
new VariableInfo("city", "java.lang.String", true,
VariableInfo.NESTED),
};
}
}
We'll also need a new entry in our TLD file:
<tag>
<name>nameInfo</name>
<tagclass>tagext.NameTag</tagclass>
<teiclass>tagext.NameTagExtraInfo</teiclass>
<bodycontent>JSP</bodycontent>
<info>Simple example of tag nesting</info>
</tag>
Let's now create a JSP to use the new tag, so that the additional lookup is performed part of the time. Of
course normally application logic would determine this, but for the sake of the example we will simply decide
this randomly.
The JSP, hello5.jsp, is very similar to the previous example:
<%@ taglib uri="/hello" prefix="examples" %>
<%
// Normally we don't declare variables, in JSPs,
// but this example should be self-contained
java.util.List names = new java.util.LinkedList();
names.add("Rod");
names.add("Isabelle");
names.add("Bob");
names.add("Jens");
New on the Java Boutique:
New Review:
Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling
API boasts simplicity, ease-of-integration, a well-rounded feature
set, and it's free!
New Applet:
Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA
sequences into three useful formats.
Elsewhere on internet.com:
WebDeveloper Java
Lots of Java information on webdeveloper.com
WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.
ScriptSearch Java
Hundreds of free Java code files to download.
jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.