【问题标题】:Why can't I iterate through a list of a Wrapper class in Salesforce Visualforce?为什么我不能遍历 Salesforce Visualforce 中的 Wrapper 类列表?
【发布时间】:2020-08-28 16:02:26
【问题描述】:

我正在尝试遍历包装类中的记录列表并将它们显示在 Visualforce 页面上。自定义对象称为 Campaign_Products__c,包装类旨在显示用户是否已选择产品添加到“购物车”。

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'

【问题讨论】:

    标签: salesforce apex visualforce


    【解决方案1】:

    您还需要使包装器中的属性对 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 方法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-10-16
      • 1970-01-01
      • 1970-01-01
      • 2015-12-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-27
      相关资源
      最近更新 更多