No Results
Search Tips:
- Please consider misspellings
- Try different search keywords
<flow:interview> を使用した高度な例
<flow:interview> コンポーネントは、複雑な Visualforce の相互作用を簡単に開発できるようにするために設計されています。カスタムコントローラを作成してフロー内の追加機能にアクセスできます。カスタムコントローラを使用すると、相互にやりとりできる複数のコンポーネントを含むペ���ジを作成できます。独自の Apex 型によって組織内のすべてのフローを個別に参照でき、フロー内の変数にはメンバー変数としてアクセスできます。
次の例では、一意の名前「ModemTroubleShooting」を持つフローは Flow.Interview.ModemTroubleShooting として参照されます。マークアップでは、ページの他の部分でフロー変数の値を表示する方法を示します。
上記のマークアップのコントローラは、次のようになります。
1<apex:page Controller="ModemTroubleShootingCustomSimple" tabStyle="Case">
2 <flow:interview name="ModemTroubleShooting" interview="{!myflow}"/>
3 <apex:outputText value="Default Case Prioriy: {!casePriority}"/>
4</apex:page>1public class ModemTroubleShootingCustomSimple {
2
3 // You don't need to explicitly instantiate the Flow object;
4 // the class constructor is invoked automatically
5
6 public Flow.Interview.ModemTroubleShooting myflow { get; set; }
7 public String casePriority;
8 public String getCasePriority() {
9 // Access flow variables as simple member variables with get/set methods
10 if(myflow == null) return 'High';
11 else return myflow.vaCasePriority;
12 }
13}カスタムコントローラを使用する場合、フローコンストラクタのフローの先頭で変数の初期値も設定できます。<apex:param> タグを使用して値を設定する場合、コンストラクタを使用して変数を渡すことは省略可能で、必須ではありません。
次は、コンストラクタのフロー変数の値を設定するカスタムコントローラの例です。
1public class ModemTroubleShootingCustomSetVariables {
2 public Flow.Interview.ModemTroubleShooting myflow { get; set; }
3
4 public ModemTroubleShootingCustomSetVariables() {
5 Map<String, Object> myMap = new Map<String, Object>();
6 myMap.put('vaCaseNumber','123456');
7 myflow = new Flow.Interview.ModemTroubleShooting(myMap);
8 }
9
10 public String caseNumber { set; }
11 public String getCaseNumber() {
12 return myflow.vaCaseNumber;
13 }
14}Flow.Interview クラスで getVariableValue メソッドを使用して、Visualforce コントローラがフロー変数の値にアクセスできるようにすることができます。変数は、Visualforce ページに埋め込まれたフローか、サブフロー要素でコールされる別のフローに含まれている場合があります。変数値は、これらのうちインタビューが現在実行されているフローから返されます。指定された変数がフロー内に見つからない場合、メソッドは null を返します。このメソッドは、コンパイル時ではなく実行時にのみ変数の存在を確認します。
次のサンプルでは、getVariableValue メソッドを使用して Visualforce ページに埋め込まれたフローからブレッドクラム (ナビゲーション) 情報を取得します。そのフローにサブフロー要素が含まれ、参照される各フローにも vaBreadCrumb 変数が含まれる場合、どのフローでインタビューが実行されているかに関わらず、すべてのフローのブレッドクラムを Visualforce ページから取得できます。
1swfobject.registerObject("clippy.codeblock-3", "9");public class SampleController {
2
3 //Instance of the flow
4 public Flow.Interview.Flow_Template_Gallery myFlow {get; set;}
5
6 public String getBreadCrumb() {
7 String aBreadCrumb;
8 if (myFlow==null) { return 'Home';}
9 else aBreadCrumb = (String) myFlow.getVariableValue('vaBreadCrumb');
10
11 return(aBreadCrumb==null ? 'Home': aBreadCrumb);
12
13 }
14}
15次の表に、フローと Apex との間での、サポートされているデータ型の名前付けの違いを示します。
| フロー | Apex |
|---|---|
| text | String |
| number | decimal |
| currency | decimal |
| date | date、dateTime |
| Boolean | Boolean |
Apex コードのテストを記述する適切な方法として、次に ModemTroubleShootingCustomSetVariables のテストクラスを作成する単純な例を挙げます。
1@isTest
2private class ModemTroubleShootingCustomSetVariablesTest {
3
4 static testmethod void ModemTroubleShootingCustomSetVariablestests() {
5 PageReference pageRef = Page.ModemTroubleShootingSetVariables;
6 Test.setCurrentPage(pageRef);
7 ModemTroubleShootingCustomSetVariables mytestController =
8 new ModemTroubleShootingCustomSetVariables();
9 System.assertEquals(mytestController.getcaseNumber(), '01212212');
10 }
11}reRender 属性の設定
reRender 属性を使用することにより、<flow:interview /> コンポーネントはページ全体を更新することなくフローを再表示します。
1<apex:page Controller="ModemTroubleShootingCustomSimple" tabStyle="Case">
2 <flow:interview name="ModemTroubleShooting" interview="{!myflow}"
3 reRender="casePrioritySection"/>
4 <apex:outputText id="casePrioritySection"
5 value="Default Case Prioriy: {!casePriority}"/>
6</apex:page>