微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

为什么不能在Salesforce Visualforce中遍历Wrapper类的列表?

如何解决为什么不能在Salesforce Visualforce中遍历Wrapper类的列表?

我试图遍历包装类内的记录列表,并在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'

解决方法

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。