Anuj was writing about the JSTL tag <c:set>, though.  JSTL de-emphasizes
scripting variables in favor of the expression language it introduces.

Scripting variables are a reasonable mechanism for some applications, but
they inherently depend on scriptlets, which means that they're useful only
if a page author knows something about Java.  Scripting variables can also
be confusing many situations.  For instance, consider the following code:

   <%-- Sets a scoped attribute "four" with the value of 4 --%>
   <c:set var="four" value="${2 + 2}"/>

   <%-- Declares a scripting variable "four" to match this scoped var --%>
   <jsp:useBean id="four" type="java.lang.Number"/>

   <%-- Replaces the scripting variablr "four" with the value 5 --%>
   <% four = new Integer(5); %>

   <%-- Prints out the value of the scoped variable "four" --%>
   <c:out value="${four}"/>

What do you expect the final <c:out> tag to output?  You might think "5"
because you replaced the scripting variable 'four' with an Integer object
for the number 5.  But the tag actually prints out "4", because changing a
scripting variable doesn't change the scoped variable that it was
originally tied to.

--
Shawn Bayern
Author, "JSP Standard Tag Library"  http://www.jstlbook.com
(coming this spring from Manning Publications)

On Mon, 11 Mar 2002, Mark R. Diggory wrote:

> See my last message about multipart stuff. You can capture this 
> functionality in TEI (TagExtraInfo) Support class to your tag. Then in 
> your tag you can set the value of the variable via a special method 
>  which you have to define.
> 
> <!-- Straight off the javadoc
> 
> public abstract class TagExtraInfo
> extends java.lang.Object
> 
> Optional class provided by the tag library author to describe additional 
> translation-time information not described in the TLD. The TagExtraInfo 
> class is mentioned in the Tag Library Descriptor file (TLD).
> 
> This class can be used:
> 
>     * to indicate that the tag defines scripting variables
>     * to perform translation-time validation of the tag attributes.
> 
> ...
> 
> -->
> -Mark Diggory
> 
> 
> Shawn Bayern wrote:
> 
> >On Mon, 11 Mar 2002, Agrawal, Anuj (Anuj)** CTR ** wrote:
> >
> >>In my code i have <c:set var="x" value="4"/>
> >>
> >>I'd like to be able to access the variable x from within a scriptlet,
> >>something like:
> >>
> >><%
> >>    x = x++;
> >>%>
> >>
> >>and vice versa.
> >>
> >>Is this even possible?  I don't see anything in the docs that refer to
> >>such interchangeability. 8(
> >>
> >
> >JSTL doesn't particularly encourage this usage, but it's perfectly
> >possible using older, scriptlet-oriented mechanisms like <jsp:useBean>.  
> >Just use a <jsp:useBean> tag after <c:set> to declare your scripting
> >variable.
> >
> >--
> >Shawn Bayern
> >Author, "JSP Standard Tag Library"  http://www.jstlbook.com
> >(coming this spring from Manning Publications)
> >
> >
> >--
> >To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
> >For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
> >
> 
> 
> 
> 
> --
> To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
> 


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to