At 8:49 AM -0600 1/28/00, Kevin Jacobson wrote:
>Hi,
>
>I am trying to figure out the purpose of the TagExtraInfo class and exactly
>when a TagExtraInfo class needs to be developed for a custom tag.

[ Quote from spec deleted. ]

>1) Does this mean that *anytime* a tag creates a scripting variable (e.g.
>via a call to pageContext.setAttribute()), a TagExtraInfo class needs to be
>developed?

Yes. The JSP container won't even look for scripting variables unless
the TLD indicates there's a TagExtraInfo class present that will tell
it about those variables.


>2) If I develop a custom tag, I can control the scoping of various
>scripting
>variables by using the various forms of pageContext.setAttribute() and
>pageContext.removeAttribute() methods in the appropriate tag methods (e.g.
>doStartTag(), doEndTag(), doAfterBody(), etc).  If this is true, what is
>the
>purpose of the TagExtraInfo class?

Actually, no you can only put scripting variables in the page scope.
This is where the container will look for the variable names it gets
from the TagExtraInfo object. You should only use the two-argument
version of pageContext.setAttribute() to set the value for a
scripting variable (i.e., pageContext.setAttribute("varName",
varValue)).


>3) What does a "typical" TagExtraInfo class look like (e.g.
>getVariableInfo())?  The JSP spec shows no examples.  Is the creation of a
>VariableInfo entry dependent upon the current state of the TagData
>instance?
>
>Here is my guess as to how the TagExtraInfo class might look for the
>following tag, does it make sense?:

You're pretty close, assuming that the object you're assigning to the
scripting variable is a String. The second argument to the
VariableInfo constructor is the class of the object that will be
assigned to the scripting variable (effectively, the type declaration
for the scripting variable). The only step you left out is adding
your new VariableInfo instance to the array before you return it,
which I added below...

>public class FooBarTagExtraInfo extends TagExtraInfo
>{
>        public VariableInfo[] getVariableInfo(TagData data)
>
>
>                // Get the value of the object we are trying to scope from
>the tag
>instance.
>                VariableInfo[] varInfoArray = null;
>                String id = data.getId();
>
>                // Only create a VariableInfo entry if the value has been
>set.
>                if (id != null)
>                {
>                        varInfoArray = new VariableInfo[1];
>                        // Create a VariableInfo object which defines that
>                        // name, type, declare, and scope of the "id"
>variable.
>                        // Scope values can be NESTED, AT_BEGIN, or AT_END
>VariableInfo
>
>                        varInfo = new VariableInfo("id",
>"java.lang.String", true, NESTED);

                         varInfoArray[0] = varInfo;


>                }
>                else
>
>
>                        // This returns an empty array
>                        varInfoArray = super.getVariableInfo(data);
>                }
>                return varInfoArray;
>        }
>}

- Mark A. Kolb                          Staff Engineer
   [EMAIL PROTECTED]                  Tivoli Systems Inc.
   http://www.cross-site.com             (512) 436-1955

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html

Reply via email to