Struts 2中的空顶部选项迭代选择

时间:2016-04-22 21:32:48

标签: java html jsp struts2

有没有办法在下面添加空顶部选择选项:

<select id="OrderNameIssueId" name="OrderWork.OrderNameIssueId" style="width: auto">
    <s:iterator value="OrderWork.ClientOrderNameIssues" status="rowIdx" id="ClientIssueOption">
        <option value='<s:property value="#ClientIssueOption.OrderNameIssue.OrderNameIssueId"/>' <s:if test="OrderWork.OrderNameIssueId != null && (OrderWork.OrderNameIssueId == #ClientIssueOption.OrderNameIssue.OrderNameIssueId)">selected</s:if><s:else></s:else>>
            <s:property value="#ClientIssueOption.OrderNameIssue.issueDescription"/>
            <s:if test="#ClientIssueOption.ApprovedOption == true">&nbsp;|&nbsp;Approved</s:if>
            <s:else>
                <s:if test="#ClientIssueOption.RequireFix == true">&nbsp;|&nbsp;Requires Fix</s:if>
                <s:else>&#9;|&nbsp;Unapproved</s:else>
            </s:else>
            &nbsp;|&nbsp;Format:&nbsp;<s:property value="#ClientIssueOption.OrderNameIssue.issueHint"/>
        </option>
    </s:iterator>
</select>

它位于使用Struts 2的JSP页面上。 选择本身是有效的,但我们需要有一个选项,它将显示在页面上,如下所示:

<option value="0">--</option>

1 个答案:

答案 0 :(得分:3)

你应该可以在“select”下面和“s:iterator”上面添加它。您还需要指定何时选择。

<select id="OrderNameIssueId" name="OrderWork.OrderNameIssueId" style="width: auto">
    <s:if test="OrderWork.OrderNameIssueId == null || OrderWork.OrderNameIssueId == 0">
        <option value="0" selected>--Please select an option--</option>
    </s:if>
    <s:else>
        <option value="0">--Please select an option--</option>
    </s:else>
    <s:iterator value="OrderWork.ClientOrderNameIssues" status="rowIdx" id="ClientIssueOption">
       <option value='<s:property value="#ClientIssueOption.OrderNameIssue.OrderNameIssueId"/>' <s:if test="OrderWork.OrderNameIssueId != null && (OrderWork.OrderNameIssueId == #ClientIssueOption.OrderNameIssue.OrderNameIssueId)">selected</s:if><s:else></s:else>>
       <s:property value="#ClientIssueOption.OrderNameIssue.issueDescription"/>
       <s:if test="#ClientIssueOption.ApprovedOption == true">&nbsp;|&nbsp;Approved</s:if>
       <s:else>
           <s:if test="#ClientIssueOption.RequireFix == true">&nbsp;|&nbsp;Requires Fix</s:if>
           <s:else>&#9;|&nbsp;Unapproved</s:else>
       </s:else>
       &nbsp;|&nbsp;Format:&nbsp;<s:property value="#ClientIssueOption.OrderNameIssue.issueHint"/>
       </option>
   </s:iterator>
</select>