At 12:40 PM -0600 1/29/00, Kevin Jacobson wrote:
>Thanks Mark,
>
>Just a few refinements please...
>
>>>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)).
>
>So, to confirm, the three-argument version of pageContext.setAttribute() is
>not intended for use *within* a Tag implementation (i.e.,
>setAttribute(String name, Object o, int scope))?  I assume then that the
>three-arg version is used internally by the JSP engine... and it is invoked
>with the scope specified within the TagExtraInfo object?

Well, the two-argument version is provided so that PageContext is
analogous to all of the other Servlet/JSP API objects that support
the various attribute methods (setAttribute(), getAttribute(),
getAttributeNames(), etc.). In addition, the PageContext class, in
its role as the Jack-of-all-Trades for accessing data from a JSP
page, provides the three-argument versions of these methods as a
convenience for accessing attributes stored in any of the four scopes.

Basically, pageContext.setAttribute(name, value) is identical to
pageContext.setAttribute(name, value, PageContext.PAGE_SCOPE).

>What is the purpose of the 3rd argument in the VariableInfo constructor
>(the
>"declare" flag)?  The JavaDoc states "declare If true, it is a new variable
>(in some languages this will require a declaration)"  Is this to
>distinguish
>between variable my tag creates and references to variables created
>elsewhere on a page?

My take on this--and I haven't found occasion to use it yet, so take
this with a grain of salt--is that if your tag is introducing a
completely new variable, then set this flag to true so the resulting
servlet will add a declaration for the variable. If, instead, your
tag is just assigning a new value to a variable that has already been
declared elsewhere (e.g., by a different custom tag), then set this
to false.

The distinction is whether code of this form should be generated:

<class> <name> = <value>;

or just this:

<name> = <value>;

- 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