リモートメソッドと継承
継承されるメソッドである Apex コントローラでリモートアクションをコールできます。@RemoteAction メソッドが検索またはコールされる場合、Visualforce ではページコントローラの継承階層を調べ、コントローラの上位階層のクラス内で @RemoteAction メソッドを検索します。
この機能を示す例を次に示します。次の Apex クラスでは 3 階層の継承階層を形成します。
1global with sharing class ChildRemoteController
2 extends ParentRemoteController { }
3global virtual with sharing class ParentRemoteController
4 extends GrandparentRemoteController { }
5
6global virtual with sharing class GrandparentRemoteController {
7 @RemoteAction
8 global static String sayHello(String helloTo) {
9 return 'Hello ' + helloTo + ' from the Grandparent.';
10 }
11}この Visualforce ページでは簡単な sayHello リモートアクションをコールします。
リモートメソッドは ChildRemoteController クラス内には存在しません。代わりに、GrandparentRemoteController から継承されます。
1<apex:page controller="ChildRemoteController" >
2 <script type="text/javascript">
3 function sayHello(helloTo) {
4 ChildRemoteController.sayHello(helloTo, function(result, event){
5 if(event.status) {
6 document.getElementById("result").innerHTML = result;
7 }
8 });
9 }
10 </script>
11
12 <button onclick="sayHello('Jude');">Say Hello</button><br/>
13 <div id="result">[Results]</div>
14
15</apex:page>