VariableInfo Class | |
Class name: | |
javax.servlet.jsp.tagext.VariableInfo |
|
Extends: | |
None |
|
Implements: | |
None |
|
Implemented by: | |
Internal container-dependent class. Most containers use the reference implementation of the class (developed in the Apache Jakarta project). |
|
Description | |
VariableInfo instances are created by TagExtraInfo subclasses to describe each scripting variable that the corresponding tag handler class creates. |
|
Example | |
Here's an example of a TagExtraInfo subclass for a custom action that creates a variable with the name specified by the id attribute and the Java type specified by the className attribute: package com.ora.jsp.tags.generic; import javax.servlet.jsp.tagext.*; public class UsePropertyTagExtraInfo extends TagExtraInfo { public VariableInfo[] getVariableInfo(TagData data) { return new VariableInfo[] { new VariableInfo( data.getAttributeString("id"), data.getAttributeString("className"), true, VariableInfo.AT_END) }; } } The web container calls getVariableInfo() during the translation phase. It returns an array of VariableInfo objects, one per variable introduced by the tag handler. The VariableInfo class is a simple bean with four properties, initialized to the values passed as arguments to the constructor: varName, className, declare, and scope. varName is simply the name of the scripting variable, and className is the name of its class. The declare property is a boolean, where true means that a brand new variable is created by the action (i.e., a declaration of the variable must be added to the generated servlet). A value of false means that the variable has already been created by another action, or another occurrence of the same action, so the generated code already contains the declaration. All the container needs to do in this case is assign a new value to the variable. The scope property has nothing to do with the JSP scopes we have seen so far (page, request, session, and application). Instead, it defines where the new variable is available to JSP scripting elements. A value of AT_BEGIN means that it is available from the action's start tag to after the action's end tag. AT_END means it is not available until after the action's end tag. A variable with scope NESTED is available only in the action's body, between the start and end tags. The scope therefore controls where the variable-declaration and value-assignment code is generated, and the tag handler class must make sure the variable is available in one of the JSP scopes at the appropriate time; e.g., in the doStartTag() method for the AT_BEGIN and NESTED scopes and the doEndTag() method for the AT_END scope. For a BodyTag that iterates over the body, the value can also be updated in the doAfterBody() method to provide a new value for each iteration. |
|
VariableInfo() | |
public VariableInfo(String varName, String className, boolean declare, int scope) |
|
Creates a new instance with the specified values. |
getClassName() | |
public String getClassName() | |
Returns the scripting variable's Java type. |
getDeclare() | |
public boolean getDeclare() | |
Returns true if the web container creates a declaration statement for the scripting variable; otherwise, returns false (used if the variable has already been declared by another tag handler and is only updated by the tag handler corresponding to the TagExtraInfo subclass creating this VariableInfo instance). |
getScope() | |
public int getScope() | |
Returns one of AT_BEGIN (makes the scripting variable available from the start tag to the end of the JSP page), AT_END (makes the variable available from after the end tag to the end of the JSP page), or NESTED (makes the variable available only between the start and stop tags). |
getVarName() | |
public String getVarName() | |
Returns the variable name. |