title: How to preselect a radio button inside of a Struts iterator based on the iterator value?
body: <p>I have the following lines of code inside of a Struts2 <code>&lt;s:iterator&gt;</code> tag.</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;s:radio name="indicatorFlag"  list = "seqNoMap" value="indicatorFlag" /&gt;&lt;/div&gt; 
  &lt;div&gt;&lt;s:property  value = "indicatorFlag"/&gt;&lt;/div&gt;
  </code></pre>
  
  <p>The <code>seqNoMap</code> is a defined on my action page as follows.</p>
  
  <pre class="lang-java prettyprint-override"><code>seqNoMap = new HashMap&lt;String, String&gt;();
  seqNoMap.put("Y", " Yes ");
  seqNoMap.put("N", " No ");
  </code></pre>
  
  <p>The radio buttons show up on my page and passes the selection info back to the <code>indicatorFlag</code> field on the action page, but the <code>value="indicatorFlag"</code> in the <code>&lt;s:radio&gt;</code> tag does not preselect the radio button even though it does print out a Y or an N in the <code>&lt;s:property&gt;</code> tag on the second line.  The <code>indicatorFlag</code> changes values as the iterator goes through the list (it is a field of the objects in the list being iterated).  I have found several places which answer this question and I think I am applying the answers they give, but obviously I am missing something.  Any help would be appreciated.</p>
  
  <p>Here is the relevant code for the <code>RefQuestionAction</code> action page.</p>
  
  <pre class="lang-java prettyprint-override"><code>private HashMap&lt;String, String&gt; seqNoMap;  
  private List&lt;RefQuestionInfo&gt; questionInfoList;
  private String indicatorFlag;       // Char (1) flag
  
  public RefQuestionAction(){
      seqNoMap = new HashMap&lt;String, String&gt;();
      seqNoMap.put("Y", " Yes ");
      seqNoMap.put("N", " No ");
  }
  </code></pre>
  
  <p>Here is the code which defines the object <code>RefQuestionInfo</code> (The <code>indicatorFlag</code> is the only field involved in this question).</p>
  
  <pre class="lang-java prettyprint-override"><code>public class RefQuestionInfo extends BaseInfo implements Serializable {
      private int questionId;             
      private int seqNo;                  
      private String indicatorFlag;       
      private Date activeDate;            
      private Date inactiveDate;          
      private String question;            
  </code></pre>
  
  <p>Here is the Struts2 code inside of the <code>&lt;s:iterator&gt;</code> tag.  I have stripped out most of the page code to focus on what my problem is.</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;s:iterator value = "questionInfoList" var = "questionInfo"&gt;
      &lt;s:radio name="indicatorFlag"  list = "seqNoMap" value="indicatorFlag" /&gt; 
      &lt;div&gt;&lt;s:property  value = "indicatorFlag"/&gt;&lt;/div&gt;
   &lt;/s:iterator&gt; 
  </code></pre>
  
  <p>The output looks like this.</p>
  
  <p><a href="https://i.stack.imgur.com/WTEnT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WTEnT.png" alt="JSP page output"></a></p>
  
  <p>I want the Yes or No radio value to be preselected based on the Y or N which is on the line after the radio buttons.</p>