为什么不能在Salesforce Visualforce中遍历Wrapper类的列表? [英] Why can't I iterate through a list of a Wrapper class in Salesforce Visualforce?

查看:152
本文介绍了为什么不能在Salesforce Visualforce中遍历Wrapper类的列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图遍历包装类内的记录列表,并在Visualforce页面上显示它们.该自定义对象称为Campaign_Products__c,包装器类旨在显示用户是否选择了要添加到购物车"中的产品.

I am trying to iterate through a list of records inside a wrapper class and show them on a Visualforce page. The custom object is called Campaign_Products__c, and the wrapper class is meant to show if the product has been selected by the user to add to a "cart".

Apex控制器代码(去除了外部位):

Apex Controller code (extraneous bits removed):

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页面(去除了多余的位)

Visualforce page (extraneous bits removed)

<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页面时出现此错误:

I get this error when trying to save the visualforce page:

Unknown property 'CONTROLLER_Store.productOption.product'

推荐答案

您还需要使包装器中的属性对VF也是可见的.像

You need to make the properties in your wrapper visible to VF too. Something like

public class productOption {
    public Campaign_Product__c product {get; private set};
    public Boolean inCart {get; set};
    public Integer quantity {get; set};
}

(假设产品在VF中应为只读).您需要这些访问修饰符或完整的getter/setter方法.

(assuming product should be readonly in VF). You need these access modifiers or full getter/setter methods.

这篇关于为什么不能在Salesforce Visualforce中遍历Wrapper类的列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆