I tried with the c:out tag within the iterate:iterate tag and it simply
print out the string, same thing if I just write the variable itself.

is the c:foreach the only way to do it? I'd rather not make a drstic change
to my site and I want to practice doing my own tag too.

> From: "Eric Plante" <[EMAIL PROTECTED]>
>
> > I have a logic:iterate on a Map. let say that the object name obj is
taken
> > out of the Map. I use obj inside the logic:iterate to get the key and
> > value of each obj without a problem.
> >
> > Now, what I need to do is to use the obj's key on another Map in the
form
> > object
> >
> > The tag is supposed to print out the String value for obj's key in
> > hashMap, obj come from treeMap.
>
> So your form has two Maps that are keyed alike?  I don't think you need a
> custom tag (or Struts tags) at all. This iterates over a treeMap and uses
> the key of each 'obj' as the key into a hashMap:
>
> <c:forEach items="${treeMap}" var="obj" >
>   ${hashMap[obj.key]}
> </c:forEach>
>
> That's with the Maps in request scope... if they're coming from the form
> bean, it would be items="${formBeanName.treeMap}" (assuming there is a
> getTreeMap method on your form bean.)
>
> The above also assumes JSTL 1.1.  If you're using JSTL 1.0 you'd need a
> <c:out value="..." /> in the
> middle rather than just the expression.
>
> Here's the JSP I was using to play with this:
> <%@ taglib uri="http://java.sun.com/jsp/jstl/core"; prefix="c" %>
>
> <%
>   java.util.TreeMap treeMap = new java.util.TreeMap();
>   treeMap.put( "key1", "value1" );
>   treeMap.put( "key2", "value2" );
>   request.setAttribute( "treeMap", treeMap );
>
>   java.util.HashMap hashMap = new java.util.HashMap();
>   hashMap.put( "value1", "description1" );
>   hashMap.put( "value2", "description2" );
>   hashMap.put( "key1",   "descByKey1" );
>   hashMap.put( "key2",   "descByKey2" );
>   request.setAttribute( "hashMap", hashMap );
> %>
>
>
> <c:forEach items="${treeMap}" var="obj" >
>   ${hashMap[obj.value]}
> </c:forEach>
>
> <hr/>
>
> <c:forEach items="${treeMap}" var="obj" >
>   ${hashMap[obj.key]}
> </c:forEach>
>
> If you need help adding JSTL to your webapp, just ask.  (We need to know
> what version of the Servlet specification you're working with-- Servlet
2.4
> (Tomcat 5.x) or something else?)
>
> HTH,
> -- 
> Wendy Smoak
>
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>


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

Reply via email to