background image

TagExtraInfo Class

<< Tags That Define Variables | Cooperating Tags >>
<< Tags That Define Variables | Cooperating Tags >>

TagExtraInfo Class

public void doTag() throws JspException, IOException {
if (iterator == null)
return;
while (iterator.hasNext()) {
getJspContext().setAttribute(var, iterator.next());
getJspBody().invoke(null);
}
}
public void setVar(String var) {
this.var = var;
}
public void setGroup(Collection group) {
this.group = group;
if(group.size() > 0)
iterator = group.iterator();
}
The scope that a variable can have is summarized in
Table 8­13
. The scope constrains the
accessibility and lifetime of the object.
TABLE 8­13
Scope of Objects
Name
Accessible From
Lifetime
page
Current page
Until the response has been sent back to the
user or the request is passed to a new page
request
Current page and any included or
forwarded pages
Until the response has been sent back to the
user
session
Current request and any subsequent
request from the same browser (subject to
session lifetime)
The life of the user's session
application
Current and any future request in the same
web application
The life of the application
TagExtraInfo
Class
"Declaring Tag Variables for Tag Handlers" on page 254
discussed how to provide information
about tag variables in the tag library descriptor. This section describes another approach:
defining a tag extra info class. You define a tag extra info class by extending the class
javax.servlet.jsp.tagext.TagExtraInfo
. A TagExtraInfo must implement the
getVariableInfo
method to return an array of VariableInfo objects containing the following
information:
Variable name
Variable class
Whether the variable refers to a new object
The availability of the variable
Programming Simple Tag Handlers
The Java EE 5 Tutorial · September 2007
262