为什么我不能在 Salesforce Visualforce 中循环访问 Wrapper class 的列表?
Why can't I iterate through a list of a Wrapper class in Salesforce Visualforce?
我正在尝试遍历包装器 class 内的记录列表,并将它们显示在 Visualforce 页面上。自定义对象称为 Campaign_Products__c,包装器 class 用于显示产品是否已被用户选择添加到“购物车”。
Apex 控制器代码(删除无关的位):
public with sharing class CONTROLLER_Store {
...
public List<productOption> cpList { get; set; }
public class productOption {
public Campaign_Product__c product;
public Boolean inCart;
public Integer quantity;
}
...
public CONTROLLER_Store(){
...
List<Campaign> cmpList = getCampaignWithProducts(CampaignId,'');
// method above calls a campaign with a related list of Campaign Product records
if(cmpList.size() > 0){
cmp = cmpList[0];
cpList = new List<productOption>();
for(Campaign_Product__c pro : cmp.Campaign_Products__r){
productOption option = new productOption();
option.product = pro;
option.inCart = false;
option.quantity = 0;
cpList.add(option);
}
} else {
cmp = new Campaign();
CampaignId = null;
cpList = new List<productOption>();
}
....
}
Visualforce 页面(删除了无关的位)
<apex:page controller="CONTROLLER_Store" >
<apex:repeat value="{! cpList }" var="option">
{!option.product.Product__r.Name}
<apex:inputCheckbox value="{! option.inCart }"/>
</apex:repeat>
</apex:page>
我在尝试保存 visualforce 页面时遇到此错误:
Unknown property 'CONTROLLER_Store.productOption.product'
您也需要使包装器中的属性对 VF 可见。像
public class productOption {
public Campaign_Product__c product {get; private set};
public Boolean inCart {get; set};
public Integer quantity {get; set};
}
(假设产品在 VF 中应该是只读的)。您需要这些访问修饰符或完整的 getter/setter 方法。
我正在尝试遍历包装器 class 内的记录列表,并将它们显示在 Visualforce 页面上。自定义对象称为 Campaign_Products__c,包装器 class 用于显示产品是否已被用户选择添加到“购物车”。
Apex 控制器代码(删除无关的位):
public with sharing class CONTROLLER_Store {
...
public List<productOption> cpList { get; set; }
public class productOption {
public Campaign_Product__c product;
public Boolean inCart;
public Integer quantity;
}
...
public CONTROLLER_Store(){
...
List<Campaign> cmpList = getCampaignWithProducts(CampaignId,'');
// method above calls a campaign with a related list of Campaign Product records
if(cmpList.size() > 0){
cmp = cmpList[0];
cpList = new List<productOption>();
for(Campaign_Product__c pro : cmp.Campaign_Products__r){
productOption option = new productOption();
option.product = pro;
option.inCart = false;
option.quantity = 0;
cpList.add(option);
}
} else {
cmp = new Campaign();
CampaignId = null;
cpList = new List<productOption>();
}
....
}
Visualforce 页面(删除了无关的位)
<apex:page controller="CONTROLLER_Store" >
<apex:repeat value="{! cpList }" var="option">
{!option.product.Product__r.Name}
<apex:inputCheckbox value="{! option.inCart }"/>
</apex:repeat>
</apex:page>
我在尝试保存 visualforce 页面时遇到此错误:
Unknown property 'CONTROLLER_Store.productOption.product'
您也需要使包装器中的属性对 VF 可见。像
public class productOption {
public Campaign_Product__c product {get; private set};
public Boolean inCart {get; set};
public Integer quantity {get; set};
}
(假设产品在 VF 中应该是只读的)。您需要这些访问修饰符或完整的 getter/setter 方法。