【问题标题】:Populate a dropdown in a visualforce page with a list of Strings使用字符串列表填充 visualforce 页面中的下拉列表
【发布时间】:2014-08-17 23:42:45
【问题描述】:

我正在尝试模仿 salesforce 潜在客户转换过程。我有一个 visualforce 页面和一个控制器。我遇到的问题是页面加载时下拉列表是空白的。我的目标是有一个字符串列表并用这个列表填充下拉列表。我搜索了高低,无法弄清楚为什么下拉列表是空白的。这是我的代码,不胜感激。

--控制器--

public with sharing class LeadConvertController {
    public Lead l {get; private set;}
    public Account a {get; private set;}
    public list<SelectOption> options {get; set;}
    public String attachToclient {get;  set;}

    public LeadConvertController(ApexPages.StandardController sc) {
        for (Lead referral : [SELECT Id, Name, Phone, OwnerId
                              FROM Lead
                              WHERE Id = : sc.getId()]) {
            l = referral;
        }

        if (l == null) {
            system.debug(logginglevel.error, 'Missing lead');
        }

        //query by name and phone to find possible Existing Accounts or contact
        options = findExistingClients(l);
    }
    public list<SelectOption> findExistingClients (Lead leadToacc) {
        list<SelectOption> findClients = new list<SelectOption>();
        for (Account acc : [SELECT Id, Name, Type, Primary_Contact__c FROM Account WHERE                                               Name = :leadToacc.Name OR Phone = :leadToacc.Phone]) {
            findClients.add( new SelectOption(acc.Id, 'Attach to Existing: ' + acc.Name));
            a = acc;
        }
        for (Contact c : [SELECT Id, Name FROM Contact WHERE Name = :leadToacc.Name OR Phone = :  leadToacc.Phone]) {
            findClients.add(new SelectOption(c.Id, 'Attach to Existing: ' + c.Name));
        }

        findClients.add(new SelectOption(l.Name, 'Create new Client/Prospect: ' + l.Name));
        return findClients;
    }
}

--visualforce 页面--

<apex:page title="Lead Convert" standardController="Lead" tabStyle="Lead" extensions="LeadConvertController">
<apex:sectionHeader title="Convert Referral" subtitle="{!l.Name}">
    <apex:outputPanel id="main" rendered="true">
        <apex:form>
            <apex:pageBlock>
                <apex:pageBlockButtons>
                    <apex:commandButton action="{!convert}" id="Convert" value="Convert" />
                    <apex:commandButton action="{!cancel}" id="Cancel" value="Cancel" />
                </apex:pageBlockButtons>
                <apex:pageBlockSection title="Convert Referral" collapsible="false" columns="1">
                    <apex:inputField label="Record Owner" value="{!l.OwnerId}" required="true" />
                    <apex:pageBlockSectionItem>
                        <apex:outputPanel>
                            <apex:outputLabel value="Client/Prospect Name" />
                            <apex:selectlist value="{!attachToclient}" required="true" />
                            <apex:selectOptions value="{!options}" />
                            <apex:outputlink title="View" value="{!a.Primary_Contact__c}">View</apex:outputlink>
                        </apex:outputPanel>
                    </apex:pageBlockSectionItem>
                </apex:pageBlockSection>
            </apex:pageBlock>
        </apex:form>
    </apex:outputPanel>
</apex:sectionHeader>
</apex:page>

【问题讨论】:

    标签: salesforce visualforce apex force.com


    【解决方案1】:

    apex:selectOptions 必须在“apex:selectlist”的开始标签和结束标签之间。

    请使用以下代码:

    <apex:page title="Lead Convert" standardController="Lead" tabStyle="Lead"     extensions="LeadConvertController">
    <apex:sectionHeader title="Convert Referral" subtitle="{!l.Name}">
    <apex:outputPanel id="main" rendered="true">
        <apex:form>
            <apex:pageBlock>
                <apex:pageBlockButtons>
                    <apex:commandButton action="{!convert}" id="Convert" value="Convert" />
                    <apex:commandButton action="{!cancel}" id="Cancel" value="Cancel" />
                </apex:pageBlockButtons>
                <apex:pageBlockSection title="Convert Referral" collapsible="false" columns="1">
                    <apex:inputField label="Record Owner" value="{!l.OwnerId}" required="true" />
                    <apex:pageBlockSectionItem>
                        <apex:outputPanel>
                            <apex:outputLabel value="Client/Prospect Name" />
                            <apex:selectlist value="{!attachToclient}" required="true" />
                            <apex:selectOptions value="{!options}" />
                            </apex:selectlist>
                            <apex:outputlink title="View" value="{!a.Primary_Contact__c}">View</apex:outputlink>
                        </apex:outputPanel>
                    </apex:pageBlockSectionItem>
                </apex:pageBlockSection>
            </apex:pageBlock>
        </apex:form>
    </apex:outputPanel>
    

    【讨论】:

      猜你喜欢
      • 2017-03-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多