如何设置默认值Combobox jsp

时间:2014-06-20 11:02:05

标签: hibernate jsp spring-mvc combobox

我想要设置默认value= ${theObject2.countryId}

<select id="locationCountry" style="padding-left: 2em" >
<option value="">Country</option>
<c:forEach  items="${countrieDetail}" var="theObject" varStatus="theCount">
<option value="${theObject.countryId}" >${theObject.countryName}</option>
</c:forEach>
</select>

1 个答案:

答案 0 :(得分:0)

您可以使用HTML selected Attribute。只需比较Id并在匹配时设置它。

示例代码:

<select id="locationCountry" style="padding-left: 2em">
    <option value="">Country</option>
    <c:forEach items="${countrieDetail}" var="theObject">
        <option value="${theObject.countryId}" <c:if test="${theObject.countryId == theObject2.countryId }">selected</c:if>>
              ${theObject.countryName}
        </option>
    </c:forEach>
</select>