I am basically looping through an Arraylist in a JSP page and I can successfully populate a Dropdown with options.
<select id="perm_bmi_stable" name="perm_bmi_stable" class="col-md-12 form-control">
<optgroup label="Stability">
<c:forEach items="${versions}" var="version">
<option value="${version.versionName}"> ${version.versionName </option>
</c:forEach>
</optgroup>
</select>
Now I need to set the proper value in the dropdown as selected depending on the value of the version.versionName value.
The Dropdown contains the following values after the for loop generates them:
- 1.0
- 2.0
- 3.0
- 4.0
If the value in the version.versionName is for example 2.0, I need the loop to set 2.0 as the dropdown's selected option.
How can I add this if condition to my for loop?
I tried this, But it doesn't work:
<option value="${version.versionName}" <c:if test="${versions[0].versionName == '${version.versionName}'}"> <c:out value="selected=selected"></c:out></c:if>>${version.versionName}</option>