<s:选择>使用Struts2中的optgroup </s:select>

时间:2013-10-24 08:23:23

标签: jsp struts2 optgroup struts1 struts-tags

我正在完成将现有Struts1应用程序迁移到Struts2的任务。我陷入了困境。在<s:select>范围内,我需要使用<optgroup>对选项进行分类。以下代码将在Struts1中执行此操作。如何使用Struts2实现这一目标?

<html:select id="foodList" property="foodItemId" onclick="selectRadio('0')">
    <c:if test="${not empty foodList1}">
        <optgroup label="Risk Analysis Report Sets">
            <c:forEach var="item" items="${foodList1}">
                <option value="${item.value}">${item.label}</option>
            </c:forEach>
        </optgroup>
    </c:if>
    <c:if test="${not empty foodList2}">
        <optgroup label="NMX Report Sets">
    <c:forEach var="item" items="${foodList2}">
                <option value="${item.value}">${item.label}</option>
            </c:forEach>
        </optgroup>
    </c:if>
    <c:if test="${not empty foodList3}">
        <optgroup label="Standard Report Sets">
            <c:forEach var="item" items="${list3}">
                <option value="${item.value}">${item.label}</option>
            </c:forEach>
        </optgroup>
    </c:if>
</html:select>

1 个答案:

答案 0 :(得分:2)

<s:optgroup/>是你的朋友。

来自Struts2 JavaDoc

  

<强> org.apache.struts2.components

     

Class OptGroup

     

创建一个需要驻留在select中的optgroup组件   标签

     

此组件将在Select组件中使用。

<s:select label = "My Selection"
           name = "mySelection"
          value = "%{'POPEYE'}"
           list = "%{#{'SUPERMAN':'Superman', 'SPIDERMAN':'spiderman'}}">

    <s:optgroup label = "Adult"
                 list = "%{#{'SOUTH_PARK':'South Park'}}" />
    <s:optgroup label = "Japanese"
                 list = "%{#{'POKEMON':'pokemon','DIGIMON':'digimon'}}" />
</s:select>