使用字符串列表填充visualforce页面中的下拉列表

时间:2014-06-26 23:56:02

标签: salesforce visualforce apex force.com

我正在尝试模仿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>

1 个答案:

答案 0 :(得分: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>

    

相关问题