Writing a custom foreach tag that exposes a nested variable
<p>I want to have a custom jsp tag that looks like this:</p>

<pre><code>&lt;custom:foreach item="&lt;%=myMap%&gt;"&gt;
   Current key: &lt;%= key %&gt;
   Current value: &lt;%= value %&gt;
&lt;/custom:foreach&gt;
</code></pre>

<p>The foreach will loop of the given list / map and expose the key / value in each iteration and evaluate them on the given body content.</p>

<p>I don't know how to expose the key and value variables into the custom foreach tag as Eclipse is telling me that "key cannot be resolved to a variable".</p>

<p>I've searched for almost an hour on google and found the following:</p>

<ul>
<li><p><a href="http://grepcode.com/file_/repository.springsource.com/javax.servlet/com.springsource.javax.servlet.jsp.jstl/1.2.0/javax/servlet/jsp/jstl/core/LoopTagSupport.java/?v=source" rel="nofollow noreferrer">http://grepcode.com/file_/repository.springsource.com/javax.servlet/com.springsource.javax.servlet.jsp.jstl/1.2.0/javax/servlet/jsp/jstl/core/LoopTagSupport.java/?v=source</a> - the actual source of the jstl foreach. They use pageContent.setAttribute() to expose the variables to the tag.</p></li>
<li><p><a href="https://stackoverflow.com/questions/6202958/nested-el-variables-for-jsp-taglibs">nested el variables for jsp taglibs</a>: Who is almost asking the same as me</p></li>
<li><p>some .tld configurations with  which did not help at all</p></li>
</ul>

<p>I currently have the following:</p>

<pre><code>for(Entry&lt;String, String&gt; entry : values.entrySet()) {
   pageContext.setAttribute("key", entry.getKey());
   out.println(getBodyContent().getString());
}
</code></pre>

<p>(located in doAfterBody()).</p>

<p>Anybody can tell me how to expose the current iteration var inside my tag?</p>

<p>Thanks!</p>