tomcat-taglibs-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Pierre Delisle <Pierre.Deli...@Sun.COM>
Subject Re: Accessing page local variables using JSTL
Date Tue, 06 May 2003 23:26:07 GMT
Hi Affan,

> How do I access local variables using JSTL <c:if>, <c:out> tags.
> 
> Example:
> <% boolean someFlag = getFlagValue(); %>

In the above code, 'someFlag' is a *scripting* variable, 
not to be confused with a *scoped* variable.

A scripting variable is accessed within Java scriptlets, as in
<% if (someFlag) { %>
   ...
<% } %>

A scoped variable is directly accessible via the EL as in:

<c:if test="${someFlag}">
   ...
</c:if>

> 
> <c:if test="${someFlag}">
>     ...... do this .....
> </c:if>
> 
> This doesn't work unless i do pageContext.setAttribute("someFlag", new
> Boolean(someFlag));

That's because ${someFlag} refers to a scoped variable, not a
scripting variable. In your example, someFlag is a scripting variable.
'pageContext.setAttribute()' makes it a scoped variable in 'page' scope.

I'd suggest you take a look at the spec (http://java.sun.com/jstl), 
or get a good book on JSTL (many are available). This will help you get 
up to speed quickly with the basic concepts involved in JSTL.

    -- Pierre

> 
> Thanks,
> 
> Affan
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: taglibs-user-help@jakarta.apache.org
> 
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-user-help@jakarta.apache.org


Mime
View raw message