Very clever!  Thank you!

Derek

-----Original Message-----
From: Kris Schneider [mailto:[EMAIL PROTECTED] 
Sent: May 27, 2004 3:26 PM
To: Tag Libraries Users List
Subject: Re: Associative array variable in JSP tag file 


I haven't had time to play with tag files much, but here's a quick
example that may help:

map.jsp:
--------
<%@ page contentType="text/plain" %>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags" %>

selected.client before: '${selected.client}'
<tags:map>
selected.client during: '${selected.client}'
</tags:map>
selected.client after: '${selected.client}'


map.tag:
--------
<%@ variable name-given="selected"
             variable-class="java.util.Map" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<jsp:useBean id="selected" class="java.util.HashMap"/>
<c:set target="${selected}" property="client" value="checked"/>
<jsp:doBody/>

output:
-------
selected.client before: ''

selected.client during: 'checked'

selected.client after: ''

The reason the value is only updated within the body of the tag is
because the default scope for the variable directive is "NESTED". That
also means you need to do something like use the <jsp:doBody> action to
actually process the body in the calling page and update the value.

Quoting Derek Mahar <[EMAIL PROTECTED]>:

> How does one create an associative array variable in a JSP tag file 
> using the EL?  I had no luck with the following attempt:
> 
> <%@ variable name-given="selected"
>   variable-class="java.util.Map"%>
> 
> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
> 
> <c:choose>
>   <c:when test="${value == 'Client'}">
>     <c:set var="selected.client" value="checked"/>
>   </c:when>
>   <c:when test="${value == 'Broker'}">
>     <c:set var="selected.broker" value="checked"/>
>   </c:when>
>   <c:when test="${value == 'Both'}">
>     <c:set var="selected.broker" value="checked"/>
>   </c:when>
>   <c:otherwise>
>     <c:set var="selected.client" value="checked"/>
>   </c:otherwise>
> </c:choose>
> 
> Thank you,
> 
> Derek
> 
> -------------------------------------
> Derek Mahar
> Software Developer
> Penson Financial Services Canada
> 360 St-Jacques St West, 12th Floor
> Montreal QC  H2Y 1P5
> 514.841.9665 x212 Phone
> 514.841.3750 Fax

-- 
Kris Schneider <mailto:[EMAIL PROTECTED]>
D.O.Tech       <http://www.dotech.com/>

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

NOTICE: This email contains privileged and confidential information and is intended 
only for the individual to whom it is addressed. If you are not the named addressee, 
you should not disseminate, distribute or copy this e-mail. Please notify the sender 
immediately by e-mail if you have received this transmission by mistake and delete 
this communication from your system. E-mail transmission cannot be guaranteed to be 
secured or error-free as information could be intercepted, corrupted, lost, destroyed, 
arrive late or incomplete, or contain viruses. 

AVIS: Le présent courriel contient des renseignements de nature privilégiée et 
confidentielle et n’est destiné qu'à la personne à qui il est adressé. Si vous n’êtes 
pas le destinataire prévu, vous êtes par les présentes avisés que toute diffusion, 
distribution ou reproduction de cette communication est strictement interdite.  Si 
vous avez reçu ce courriel par erreur, veuillez en aviser immédiatement l’expéditeur 
et le supprimer de votre système. Notez que la transmission de courriel ne peut en 
aucun cas être considéré comme inviolable ou exempt d’erreur puisque les informations 
qu’il contient pourraient être interceptés, corrompues, perdues, détruites, arrivées 
en retard ou incomplètes ou contenir un virus.  

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

Reply via email to