On Wed, 6 Nov 2002, Joel Carklin wrote:

> I'm looking for a tag that will take a hashmap as a attribute, like
> the jstl iterator tag, but instead of iterating over the tag I want to
> be able to display the value by giving it the key. The idea is that a
> user fills in a form and a servlet generates a hashmap of validation
> errors. the key in the hashmap corresponds to the name of the invalid
> form field, and the value that goes with that key is a description of
> the error...

You can do this with JSTL; just don't use the iterator (c:forEach) tag you
mention.  Instead, you could use expressions in tags like

  <c:out value="${myMap.key}"/>

This will print the value for myMap.get("key"), assuming of course that
the scoped 'myMap' variable is a Map.  (Whether it's a HashMap or not
isn't relevant; it's useful to think in terms of interfaces provided by
the Collections framework, not in terms of their implementations.)

--
Shawn Bayern
"JSTL in Action"   http://www.manning.com/bayern

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://archives.java.sun.com/jsp-interest.html
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.jsp
 http://www.jguru.com/faq/index.jsp
 http://www.jspinsider.com

Reply via email to