0

我在一个名为“Lead Process”的文件夹中管理了一些电子邮件模板,那里大约有 12 个电子邮件模板。

所以我需要一个下拉菜单在我的 VF 页面中显示该文件夹中的所有电子邮件模板。当用户从下拉列表中选择模板时,文本或 html 将显示在下拉列表下方的富文本框中。

好吧,在其他语言中,例如在 dotnet 中,我们只需在下拉菜单中触发onChange事件或onSelect事件,然后通过 id 我们获取 html 内容并将其粘贴到富文本框中……所有这些事情都发生在 javascript 中。

在销售人员中是否可行。如果,请给我一些想法。怎么可能?。

4

1 回答 1

0

I think you're interested in the <apex:actionSupport> VF tag, which allows you to call an action method in the controller and refresh and component on the page when an action is performed on a form element. In this case you would want bind it to the onchange event of your <apex:selectList>.

I had recently put together something similar for another project, so I changed it a bit to generalize it for you. The page/controller below should allow you to view email templates in any folder...you should be able to modify it for your purposes without too much difficulty.

VF page:

<apex:page controller="SomeController">
    <apex:form>
        <apex:pageBlock title="View Email Template" id="emailTemplateBlock">
            Select Email Template Folder:
            <apex:selectList value="{!selectedEmailTemplateFolder}" multiselect="false" size="1">
                <apex:selectOptions value="{!emailTemplateFolderOpts}" />
                <apex:actionSupport event="onchange" action="{!refreshEmailTemplateSection}" rerender="emailTemplateBlock" />
            </apex:selectList>
            <br/>
            Select Email Template: 
            <apex:selectList value="{!selectedEmailTemplate}" multiselect="false" size="1">
                <apex:selectOptions value="{!emailTemplateOpts}" />
                <apex:actionSupport event="onchange" action="{!refreshEmailTemplateSection}" rerender="emailTemplateBlock" />
            </apex:selectList>
            <br/>
            <apex:outputPanel id="emailTemplateContentPanel" rendered="{!NOT(ISNULL(chosenEmailTemplate))}">
                <p><b>{!chosenEmailTemplate.Name} - Subject:</b> {!chosenEmailTemplate.Subject}</p>
                <pre>{!chosenEmailTemplate.Body}</pre>
            </apex:outputPanel>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Controller:

public class SomeController {

    private List<EmailTemplate> allEmailTemplates;
    private List<Folder> allEmailTemplateFolders;
    public String selectedEmailTemplateFolder {public get; public set;}
    public String selectedEmailTemplate {public get; public set;}
    public EmailTemplate chosenEmailTemplate {public get; private set;}

    public SomeController() {
        allEmailTemplates = [select Id, Name, Subject, Body, FolderId from EmailTemplate order by Name asc];
        allEmailTemplateFolders = [select Id, Name from Folder where Type = 'Email' order by Name asc];
    }

    public List<SelectOption> getEmailTemplateFolderOpts() {
        List<SelectOption> opts = new List<SelectOption>();
        opts.add(new SelectOption('null', ' - Select - '));
        for ( Folder f : allEmailTemplateFolders )
            opts.add(new SelectOption(f.Id, f.Name));
        // add an option for templates in the Unfiled Public folder
        opts.add(new SelectOption(UserInfo.getOrganizationId(), 'Unfiled Public'));
        return opts;
    }

    public List<SelectOption> getEmailTemplateOpts() {
        List<SelectOption> opts = new List<SelectOption>();
        if ( selectedEmailTemplateFolder != null ) {
            opts.add(new SelectOption('null', ' - Select - '));
            Id selectedId = (Id) selectedEmailTemplateFolder;
            for ( EmailTemplate et : allEmailTemplates ) {
                if ( et.FolderId == selectedId )
                    opts.add(new SelectOption(et.Id, et.Name));
            }
        }
        return opts;
    }

    public PageReference refreshEmailTemplateSection() {
        // this is a bit ugly, but a consequence of not being able to set a SelectOption's value to null
        if ( selectedEmailTemplateFolder == null || selectedEmailTemplateFolder == 'null' ) {
            selectedEmailTemplateFolder = null;
            selectedEmailTemplate = null;
        }
        if ( selectedEmailTemplate == null || selectedEmailTemplate == 'null' ) {
            selectedEmailTemplate = null;
            chosenEmailTemplate = null;
        } else {
            Id selectedId = (Id) selectedEmailTemplate;
            for ( EmailTemplate et : allEmailTemplates ) {
                if ( et.Id == selectedId ) {
                    chosenEmailTemplate = et;
                    break;
                }
            }
        }
        return null;
    }
}
于 2012-08-02T15:20:52.667 回答