struts2列表框中的默认值

Sou*_*abh 3 jsp struts struts2 listbox jsp-tags

我们有列表框.这将显示美国的不同州.我希望状态"LA"应该被预选.但我不知道列表中"LA"的位置.它可能会有所不同.我们正在使用以下脚本.

<select id="state" name="state" title="State" class="js_required prompt_text grid_2" tabindex="5">
                <option>State</option>
                <s:iterator value="@com.homeservices.action.utils.StateCode@values()">
                    <option value="<s:property/>"><s:property/></option>
                </s:iterator>
</select>
Run Code Online (Sandbox Code Playgroud)

var @ com.homeservices.action.utils.StateCode @ values()给出了一个值列表:

AA
AE
AK
CA
CT
IL
LA
MA
MD
Run Code Online (Sandbox Code Playgroud)

......等等.

有人可以建议如何使洛杉矶成为一个预先选定的州.

Ste*_*tez 5

Struts方法

<s:select id="state"
          name="state"
          title="State"
          headerKey=""
          headerValue="State"
          list="@action.StateCode@values()"
          cssClass="js_required prompt_text grid_2"
          value="@action.StateCode@LA"
          tabindex="5"/>
Run Code Online (Sandbox Code Playgroud)

JSP方法(JSTL/JSP-EL)

<%@ page import="action.StateCode" %>
<c:set var="states" value="<%=StateCode.values()%>"/>

<select id="state" name="state" title="State"
        class="js_required prompt_text grid_2" tabindex="5">
    <option>State</option>
    <c:forEach items="${states}" var="state">
        <option value="${state}" ${state == 'LA' ? 'selected="selected"' : ''}>${state}</option>
    </c:forEach>
</select>
Run Code Online (Sandbox Code Playgroud)