[英]How to null check variable of list type using struts2 <s:if> tag
I have list of Payment Gateway retrieved from requestAttribute on my Jsp as below : 我有从Jsp上的requestAttribute检索到的Payment Gateway的列表,如下所示:
List<String> payGwList = (List<String>)request.getAttribute("payGwList");
I have to populate them in my select-box(combo-box) but before that have to do following check 我必须将它们填充到我的选择框(组合框)中,但在此之前必须执行以下检查
EDIT 编辑
- Null Check 空检查
- size > 1 Check 大小> 1检查
My Code is : 我的代码是:
<%
<%if(payGwList != null && payGwList.size() > 1){ //edited
%>
<tr id="paygwrowid" >
<td width="112" class="content">
<s:label key="payment.paymentgateway"/><span class="requiredData">*</span>
</td>
<td colspan="2" class="content">
<select name="paymentGateway" id="paymentGateway" class="content" style="width:189px;">
<option value="0">--Select--</option>
<%if(payGwList != null && !payGwList.isEmpty()){
for(String paymentGateway : payGwList){
%>
<option value="<%=paymentGateway%>"><%= paymentGateway%></option>
<%}}%>
</select>
</td>
</tr>
<%}%>
But how to do achieve the same using <s:if>
tag as i dont want to use scriptlets on my jsp. 但是如何使用<s:if>
标记实现相同的目标,因为我不想在jsp上使用scriptlet。
<% if(payGwList != null){ %>
= <s:if test="payGwList != null">
, while <% if(payGwList != null){ %>
= <s:if test="payGwList != null">
,而
<select name="paymentGateway" id="paymentGateway" class="content" style="width:189px;">
<option value="0">--Select--</option>
<%if(payGwList != null && !payGwList.isEmpty()){
for(String paymentGateway : payGwList){
%>
<option value="<%=paymentGateway%>"><%= paymentGateway%></option>
<%}}%>
</select>
becomes simply 变得简单
<s:select list = "payGwList"
listKey = "paymentGateway"
listValue = "paymentGateway"
headerKey = "0"
headerValue = "--Select--"
name = "paymentGateway"
id = "paymentGateway"
cssClass = "content"
cssStyle = "width: 189px;"
/>
listValue
and listKey
are not even necessary here because you are using the same value for both of them. 在这里甚至没有必要使用listValue
和listKey
,因为它们使用的是相同的值。
Avoid Scritplets and be sure to use all the power of the framework through its UI Tags too. 避免使用Scritplet,并确保也通过其UI标签使用框架的所有功能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.