3
我有一個jsp頁面,其中有一個選擇框,其中有一個選項列表。在struts 2中檢查等於動作變量和列表變量?
我正在使用s:if
檢查等號,以便我可以顯示選項。
我的代碼是:
<select class="dropbox" name="campaign" id="campaign" onchange="getCampaignQuestion();">
<option value="">- Please Select -</option>
<s:iterator var="AR" value="campaignList" status="currRow">
<s:if test="%{campaignId==#AR.campaignId}">
<option value='<s:property value="%{campaignId}" />' selected >
<s:property value="%{campaignName}" />
</option>
</s:if>
<s:else>
<option value='<s:property value="%{campaignId}" />'>
<s:property value="%{campaignName}" />
</option>
</s:else>
</s:iterator>
</select>
運動類
import java.util.Date;
import java.util.HashMap;
import java.util.List;
public class Campaign {
private long campaignId;
private long customerId;
private int noOfOutlets;
private String campaignName;
private String customerName;
private Date startDate;
private Date expiryDate;
private String strStartDate;
private String strExpiryDate;
private String status;
private List<Outlet> outletList;
private String outletStatus;
private List<Outlet> userOutletList;
public List<Outlet> getUserOutletList() {
return userOutletList;
}
public void setUserOutletList(List<Outlet> userOutletList) {
this.userOutletList = userOutletList;
}
public String getOutletStatus() {
return outletStatus;
}
public void setOutletStatus(String outletStatus) {
this.outletStatus = outletStatus;
}
public List<Outlet> getOutletList() {
return outletList;
}
public void setOutletList(List<Outlet> outletList) {
this.outletList = outletList;
}
public int getNoOfOutlets() {
return noOfOutlets;
}
public void setNoOfOutlets(int noOfOutlets) {
this.noOfOutlets = noOfOutlets;
}
public String getStrStartDate() {
return strStartDate;
}
public void setStrStartDate(String strStartDate) {
this.strStartDate = strStartDate;
}
public String getStrExpiryDate() {
return strExpiryDate;
}
public void setStrExpiryDate(String strExpiryDate) {
this.strExpiryDate = strExpiryDate;
}
public long getCustomerId() {
return customerId;
}
public void setCustomerId(long customerId) {
this.customerId = customerId;
}
public long getCampaignId() {
return campaignId;
}
public void setCampaignId(long campaignId) {
this.campaignId = campaignId;
}
public String getCampaignName() {
return campaignName;
}
public void setCampaignName(String campaignName) {
this.campaignName = campaignName;
}
public String getCustomerName() {
return customerName;
}
public void setCustomerName(String customerName) {
this.customerName = customerName;
}
public Date getStartDate() {
return startDate;
}
public void setStartDate(Date startDate) {
this.startDate = startDate;
}
public Date getExpiryDate() {
return expiryDate;
}
public void setExpiryDate(Date expiryDate) {
this.expiryDate = expiryDate;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
}
這裏campaignList是運動類對象的列表。
因此,在s:if
標記我想檢查具有相同名稱的列表變量和動作變量之間的相等性。
像這樣:
<s:if test="%{campaignId==#AR.campaignId}">
,但它不工作。