2012-08-01 65 views
0

我有一些電子郵件模板管理一個文件夾名稱「主要過程」,約12電子郵件模板那裏。獲取電子郵件模板並顯示名稱下拉在VF頁面

所以我需要在我的音頻頁面顯示該文件夾中的所有電子郵件模板的下拉列表。當用戶從下拉列表中選擇模板時,文本或html將顯示在下拉菜單下方的Richtext框中。

那麼在其他的langauge像DOTNET我們剛剛火在下拉列表中onChange事件或onSelect事件和ID,我們得到的HTML內容,並將其粘貼在富文本框...在javascript所有這些事情發生在那裏。

銷售人員是否可行?如果是的請給我一些想法。怎麼可能?

回答

0

我認爲您對<apex:actionSupport> VF標籤感興趣,它允許您在表單元素上執行操作時調用控制器中的操作方法和頁面上的刷新和組件。在這種情況下,您需要將其綁定到您的<apex:selectList>onchange事件。

我最近爲另一個項目組合了一些類似的東西,所以我對它進行了一些改動,以便爲您概括它。下面的頁面/控制器應該允許您查看任何文件夾中的電子郵件模板......您應該可以根據自己的目的修改它,而不會有太多困難。

VF頁:

<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> 

控制器:

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; 
    } 
} 
相關問題