<apex:actionSupport>
フォーム要素でアクションが実行されたときに、コントローラーでアクション メソッドを呼び出し、ページの更新とコンポーネントを実行できる VF タグに興味があると思います。onchange
この場合、それをあなたのイベントにバインドしたいと思うでしょう<apex:selectList>
。
最近、別のプロジェクトで似たようなものをまとめたので、一般化するために少し変更しました。以下のページ/コントローラーを使用すると、任意のフォルダーにある電子メール テンプレートを表示できるはずです...目的に合わせてそれほど困難なく変更できるはずです。
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;
}
}