tomcat-taglibs-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dave Newton <d...@solaraccess.com>
Subject Re: [JSTL] Help hiding/showing sections on JSP (w/ cookie?)
Date Thu, 19 Dec 2002 21:38:17 GMT
Shawn Bayern wrote:

>On Thu, 19 Dec 2002, Wendy Smoak wrote:
>
>  
>
>>   <x:if select="{$showAddress}" >
>>     <table><tr><td>stuff</td></tr></table>
>>   </x:if>
>>
>>Or can I get at the cookie with JSTL?  (And pick out a specific position of
>>it??)  The setting of the cookie is done in a Struts Action, so I've got
>>Struts (and Struts-EL) tags available if one of those would be easier to
>>use.
>>    
>>
>
>You can indeed read the cookie with expressions like ${cookie.key} in most
>cases, but you won't be able to get at a character position easily in the
>cookie -- at least not under JSTL 1.0.  However, if you delimit the
>cookie's value with commas (e.g., "Y,N,N,Y,..."), you could in principle
>loop over the cookie's components with <c:forEach> and set different
>variables depending on what each individual value equals.  The rough form
>of this solution looks like
>
> <c:forEach items="${cookie.foo}" var="e" varStatus="c">
>  <c:if test="${e == 'Y'}">
>   <c:set target="${myMap}" property="boolean${c.count}" value="${true}" />
>  </c:if>
> </c:forEach>
>
>  
>
Glass houses, stones, and all, but I think it's a yicky solution, far 
too dependent on nothing ever changing :) If I were doing it I'd explore 
other options (storing user prefs in a db indexed by a cookie value, for 
instance) and work off of that. Having position-dependent values seems 
an invitation to fragility.

If you're dead-set on positional keys, maybe just using an integer and 
doing bit compares (I don't know how/if that works under JSTL, but it's 
a trivial custom tag) or something... Or just use a custom tag for the 
YNYNYYNN method, I suppose. Obviously the db (or similar) solution is 
more robust and mutable.

Just my $0.02, sorry :)

Dave


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


Mime
View raw message