You retrieve the value using your data access classes and then when you build the options for the edit screen you set the selected flag
If you are hard coding country options on the page you would use
- <c:choose>
-
<c:when test="${databaseValue == 1}">
-
<option value="1" selected>
-
<c:out value="India" />
-
</option>
-
</c:when>
-
<c:otherwise>
-
<option value="1">
-
<c:out value="India" />
-
</option>
-
</c:otherwise>
-
</c:choose>
With hard coding you would do this for every one of your options.
If you took earlier advise and put all those countries into a List then your code is much simpler and shorter, just something like
-
<select name="countryId">
-
<c:forEach var="country" items="${countries}" >
-
<c:choose>
-
<c:when test="${databaseValue == country.id}">
-
<option value="${country.id} selected>
-
<c:out value="${country.name}" />
-
</option>
-
</c:when>
-
<c:otherwise>
-
<option value="${country.id}">
-
<c:out value="${country.name}" />
-
</option>
-
</c:otherwise>
-
</c:choose>
-
</c:forEach>
-
</select>
-
-
-
and it would cover all countries.