首页 > 解决方案 > 无法从组件控制器获取值到 visualforce 自定义组件

问题描述

我必须在 visualforce 组件中显示客户详细信息。我能够从包装类获取值到 vf 组件控制器,但无法使用 apex:repeat 在 VF 组件中显示值。我正在使用 Map 在组件中显示值,因为一个客户可能有 1 个或多个记录,因此我需要将客户 ID 显示为标题,在此标题下我需要显示此客户记录,然后是第二个客户等等。 ..

****VF Component****

<apex:component controller="CustSrchController">
    <apex:attribute name="custExtId" type="String" description="passing customer external Id" assignTo="{!CustomerExtId}"/>
    <apex:pageBlock title="Customer Details 4...">
        <apex:repeat value="{!PackageMap1}" var="cust2">
        <apex:outputText value="{!PackageMap1[cust2]}" />
            <apex:pageBlockSection columns="3">
                <apex:facet name="header"> Customer Id {!PackageMap1[cust2].custId}</apex:facet>
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Card Number" for="custCC" />
                    <apex:outputText value="{!PackageMap1[cust2].custCC}" id="custCC" />
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Account Id" for="custAccID" />
                    <apex:outputText value="{!PackageMap1[cust2].custAccID}" id="custAccID" />
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>
        </apex:repeat>
    </apex:pageBlock>
</apex:component>

****VF Component Controller****

public class CustSrchController {

public String CustomerExtId;

public void setCustomerExtId (String s) {
    CustomerExtId = s.toUpperCase();
}
    
public String getCustomerExtId() {
    return CustomerExtId;
} 

public list<WrapperResponses.Customers> lstCustomer{get;set;}
public List<WrapperResponses.Customers> lstCustExtDetailsSearch{get;private set;}

List<String> custList = new List<String>();
public Map<string,WrapperResponses.Customers> custMap = new Map <string,WrapperResponses.Customers>();
public Map<string,List<String>> custMap1 = new Map <string,List<String>>();

    public void CustomerDetails(){
    //public void getCustomerDetails(){

        WrapperResponses.CustInquiryResp cust = APIController.getCustomerInquiry('ABC',CustomerExtId,'PQR');
        lstCustomer = cust.customers;

        WrapperResponses.CustSearchResp custSearch = APIController.searchCustomers('LNAME','FNAME','M','1234','1234567890','A1','123456','abc@gmail.com');        
        lstCustExtDetailsSearch = custSearch.customers;

        for (WrapperResponses.Customers custItem : lstCustomer) {
            custList.add(custItem.custId);
            custList.add(custItem.custCC);
            custList.add(custItem.custAccID);
            
            custMap.put(custItem.customerExternalIdentifier, custItem);
            //custMap.put(custItem.customerExternalIdentifier, custList);
            custMap1.put(custItem.customerExternalIdentifier, custList);
        }
    }
    
    public Map<string,WrapperResponses.Customers> getPackageMap() {
        return custMap;
    }
    
    public Map<string,List<String>> getPackageMap1() {
        return custMap1;
    }
}

****Wrapper Class****
public with sharing class WrapperResponses {
    public WrapperResponses() {

    }
    //API Response for Customer Inquiry API
    public class CustInquiryResp{
        public List<Customers> customers;
    }

    // API Response for Customer Search API
    public class CustSearchResp{
        public List<Customers> customers;
    }

    //Dummy API to get Customer Response
    public class Customers {
        //these are from inquiry api
        public String customerId{get;}
        public String customerCC{get;}
        public String customerAccId{get;}
    }
}

标签: apex

解决方案


推荐阅读