You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-user@tomcat.apache.org by Derek Mahar <DM...@penson.ca> on 2004/05/27 19:04:25 UTC

Associative array variable in JSP tag file

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
-------------------------------------
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: taglibs-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-user-help@jakarta.apache.org


Re: Associative array variable in JSP tag file

Posted by Kris Schneider <kr...@dotech.com>.
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 <DM...@penson.ca>:

> 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 <ma...@dotech.com>
D.O.Tech       <http://www.dotech.com/>

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