Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here is a demo that loops through lists of map:</p> <pre class="lang-java prettyprint-override"><code>import com.opensymphony.xwork2.ActionSupport; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; public class mapTest extends ActionSupport { public List&lt;Map&gt; listmap; public String execute(){ listmap = new ArrayList(); Map map = new HashMap(); map.put("a", "alpha"); map.put("b", "bravo"); map.put("c", "charlie"); listmap.add(map); Map map2 = new HashMap(); map2.put("d", "delta"); map2.put("e", "echo"); map2.put("f", "foxtrot"); listmap.add(map2); return SUCCESS; } } </code></pre> <p>Here is the JSP to render it:</p> <pre class="lang-xml prettyprint-override"><code>&lt;%@taglib prefix="s" uri="/struts-tags"%&gt; &lt;%@page contentType="text/html" pageEncoding="UTF-8"%&gt; &lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt; &lt;html&gt; &lt;body&gt; &lt;h1&gt;Map Test&lt;/h1&gt; &lt;table&gt; &lt;thead&gt; &lt;tr&gt; &lt;th&gt;List #&lt;/th&gt; &lt;th&gt;key&lt;/th&gt; &lt;th&gt;value&lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;tbody&gt; &lt;s:iterator value="listmap" status="stat"&gt; &lt;s:iterator&gt; &lt;tr&gt; &lt;th&gt;&lt;s:property value="#stat.index"/&gt;&lt;/th&gt; &lt;td&gt;&lt;s:property value="key"/&gt;&lt;/td&gt; &lt;td&gt;&lt;s:property value="value"/&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/s:iterator&gt; &lt;/s:iterator&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Note the inner iterator is context sensitive it will use the last value pushed onto the stack. The status attribute gives us a IteratorStatus object each iteration which is useful if we want to know the current iteration.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload