gpt4 book ai didi

java - 检查等于 struts 2 中的 Action 变量和列表变量?

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:19:05 24 4
gpt4 key购买 nike

我有一个 jsp 页面,其中有一个选择框,其中有一个选项列表。

我正在使用 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>

Activity 类

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 是 Campaign 类对象的列表。

所以在 s:if 标签中,我想检查具有相同名称的列表变量和 Action 变量之间的相等性。

像这样:

<s:if test="%{campaignId==#AR.campaignId}">

但它不起作用。

最佳答案

要在迭代具有同名变量的对象时访问 Action 变量,您可以使用 #action引用 Action 的一个:

<s:if test="%{ #action.campaignId == #AR.campaignId }">

但最好将代码简化为直接的 <s:select />标签:

<s:select cssClass="dropbox" 
name="campaign"
id="campaign"
onchange="getCampaignQuestion();"
headerKey=""
headerValue="- Please Select -"
list="campaignList"
listKey="campaignId"
listValue="campaignName"
value="campaignId" /> <!-- no iteration, no need to differentiate it here -->

更干净一些,不是吗?

关于java - 检查等于 struts 2 中的 Action 变量和列表变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31117157/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com