title: Struts2 map with dynamic key
body: <p><strong>jsp</strong></p>
  
  
  
  <pre class="lang-jsp prettyprint-override"><code>&lt;s:set var="cnt" value="1" /&gt;
  &lt;s:iterator value="assemblydebates"&gt;
  &lt;s:if test='%{(#cnt%4)==1}'&gt;
  &lt;h4 style="color: #FACC2E;" class="text-left"&gt;&lt;s:property value="archives1[#cnt]"/&gt;&lt;/h4&gt;
  &lt;/s:if&gt;
  ..................
  &lt;s:set var="cnt" value="%{#cnt + 1}"/&gt;
  &lt;/s:iterator&gt;
  </code></pre>
  
  <p>Where <code>archives1</code> is a map <code>(LinkedHashMap&lt;String,String&gt;)</code> of values <code>{4=Assembly Debates, 8=Party Press Meets, 12=Promos, 16=Archives}</code>.</p>
  
  <p><strong>Problem</strong> with above code. Here <code>archives1[#cnt]</code> is not printed. If I use like <code>archives1['4']</code> then its printing. </p>
  
  <p>And I also checked through iterator</p>
  
  <pre class="lang-jsp prettyprint-override"><code>&lt;s:iterator value="archives1"&gt;  
  &lt;span id="pid" style="cursor:pointer;" onClick="getvideos('&lt;s:property value='value'/&gt;');"&gt;&lt;s:property value='value'/&gt;&lt;/span&gt; 
  &lt;/s:iterator&gt;
  </code></pre>
  
  <p>This piece of code is working.</p>
  
  <p>Can any one tell me that whats the problem here.</p>
  
  <p><strong>Edit:</strong></p>
  
  <pre class="lang-jsp prettyprint-override"><code>  &lt;s:set var="cnt" value="%{1}" /&gt;
    &lt;s:iterator value="assemblydebates"&gt;
    &lt;s:if test='%{(#cnt%4)==1}'&gt;
    &lt;h4 style="color: #FACC2E;" class="text-left"&gt;&lt;s:property value="archives1[#cnt]"/&gt;&lt;/h4&gt;
    &lt;/s:if&gt;
    &lt;s:if test='%{(#cnt%4)==0}'&gt;
    &lt;div style="display:inline-block;background-color: #ffffff;"&gt;&lt;img src="images/more1.png" title="Read more.." style="width:30px;height:30px;cursor:pointer;" onClick="getvideos('&lt;s:property value="%{archives1[#cnt]}"/&gt;');"/&gt;&lt;/div&gt;
    &lt;/s:if&gt;
    &lt;s:set var="cnt" value="%{#cnt+1}"/&gt;
    &lt;/s:iterator&gt;
  </code></pre>
  
  <p><strong>Problem:</strong>  <code>&lt;h4 style="color: #FACC2E;" class="text-left"&gt;&lt;s:property value="archives1[#cnt]"/&gt;&lt;/h4&gt;</code> not prints a value</p>
  
  <p>If I try <code>&lt;h4 style="color: #FACC2E;" class="text-left"&gt;&lt;s:property value="archives1['4']"/&gt;&lt;/h4&gt;</code> it prints a value. So <code>if</code> condition evaluated.</p>
  
  <p>The remaining code works well.</p>