【问题标题】:How to set default value Combobox jsp如何设置默认值组合框jsp
【发布时间】:2014-06-23 16:26:38
【问题描述】:

我想设置默认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>

【问题讨论】:

  • 你不能在你支持表单的模型属性中设置默认值吗?然后 Spring 将使用该值渲染组件。
  • 为什么是 theObject2 ? “2”是错字吗?

标签: hibernate jsp spring-mvc combobox


【解决方案1】:

您可以使用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>

【讨论】:

猜你喜欢
  • 2017-10-03
  • 2014-02-14
  • 2014-02-15
  • 2013-01-13
  • 1970-01-01
  • 1970-01-01
  • 2016-04-29
  • 1970-01-01
相关资源
最近更新 更多