title: dynamic field name for field validator in struts2
body: <p>i have this Class</p>
  
  <pre><code>public Class Employee
  {
      String name;
      List&lt;Address&gt; listOfAddress;
  }
  
  public Class Address
  {
      String location;
      String streetName;
  }
  </code></pre>
  
  <p>in my JSP page i have filled like this</p>
  
  <pre><code> &lt;s:textfield id="streetName" name="listOfAddress[%{listOfAddress.size()}].streetName" size="20" maxlength="24" cssStyle="width: 100px" /&gt;
  </code></pre>
  
  <p>each time i submit the page an object of time Address is added to the list therefore the size will increase by one.
  when i view the source HTML of the previous textField, its name looks like this listOfAddress[0].streetName , if i submit the JSP page after succefull addition, it will return to the same page and the name of this textfield will be listOfAddress[1].streetName
  if you view its HTML source</p>
  
  <p>and like this i can add as many addresses as i want to same Employee object.</p>
  
  <p>so far everything is OK. the problem is when i want to validate this field ican't because it is dynamic
  if i put this validation it will validate it the first time only.</p>
  
  <pre><code>     &lt;field name="listOfAddress[0].streetName"&gt;
          &lt;field-validator type="requiredstring" short-circuit="true"&gt;
             &lt;param name="trim"&gt;true&lt;/param&gt;
             &lt;message&gt;sorry this field is required field&lt;/message&gt;
         &lt;/field-validator&gt;
      &lt;/field&gt; 
  </code></pre>
  
  <p>what i want is to make the index of the list "listOfAddress" dymanic according to the size of the list.</p>
  
  <p>i don't know how to pass it dynamicall from the jsp</p>
  
  <p>can i do something like this ?</p>
  
  <pre><code>    &lt;field name="listOfAddress[**${dynamic index value}**].streetName"&gt;
          &lt;field-validator type="requiredstring" short-circuit="true"&gt;
             &lt;param name="trim"&gt;true&lt;/param&gt;
  
             **&lt;param name="myIndex"&gt;${dynamic index value}&lt;/param&gt;**
  
             &lt;message&gt;sorry this field is required field&lt;/message&gt;
         &lt;/field-validator&gt;
      &lt;/field&gt; 
  </code></pre>
  
  <p>or pass the dynamic value to a custom validator ?</p>
  
  <p>please help me, how to validate the list when the index is dynamic</p>