title: Set value of bean attribute on Drop Down selection: Spring
body: <p>I am using <code>JSTL</code> to populate drop down items, where country is an item having  <code>{ id, name, code }</code> attributes.</p>
  
  <p><em><strong>My need is to get name and code for selected country.</em></strong></p>
  
  <p><em>for example:</em></p>
  
  <p><code>Country{c_id, c_name, c_code}</code> is structure of country bean. when user selects this item I need to retrieve two values c_name, c_code.</p>
  
  <p><em><strong>What I did yet:</em></strong></p>
  
  <p>As I know, only one value can be assigned to <code>itemValue</code> either <code>c_name</code> or <code>c_code</code>.
  I tried to populate all country and match selected country and then set to another path variable, but this also not working.</p>
  
  <p><em><strong>My code is as</em></strong></p>
  
  <pre><code>&lt;form:select path="selectedCountry" id="ddlCountryId"&gt;
  &lt;c:forEach items="${countries}" var="country"&gt;
      &lt;option value="${country.countryName}" ${country.countryName == selectedCountry ? 'selected' : ''}&gt;${country.countryName}&lt;/option&gt;
      &lt;/c:forEach&gt;
      &lt;/form:select&gt;
      &lt;input class="login_submit" type="submit" value="Login" id="btnSubmitId"&gt;
  
      &lt;!-- Read country code of selected country --&gt;
      &lt;c:forEach var="country" items="${countries}"&gt;
          &lt;c:out value="country"&gt;&lt;/c:out&gt;
          &lt;c:choose&gt;
          &lt;c:when test="${country.countryName==loginCreadetials.selectedCountry}"&gt;
          &lt;input name="countryCode" type="hidden" value="${country.countryCode}"/&gt;
  
          &lt;/c:when&gt;
          &lt;/c:choose&gt;
      &lt;/c:forEach&gt;
  </code></pre>
  
  <p>How can I do this? </p>