2011-01-11 12 views
4

私はbeforeInterceptorのクラスから継承するコントローラを持っています。どのようにしてBeforeInterceptorsをチェーン化しますか?

ここは私の基本クラスです。

class FooBase { 
    def beforeInterceptor = [action: {parentInterceptor()}] 

    def parentInterceptor() { 
     render("Snarge") 
    } 
} 

ここでは動作しないコントローラのバージョンです。ここで

class BrokenController extends FooBase 
{ 
    def beforeInterceptor = [action: {childInterceptor()}] 

    def childInterceptor() { 
     super.beforeInterceptor.action.call() 
     render("Bar") 
    } 

    def index = { 
     render("Foo") 
    } 
} 

は、私がWorkingControllerにインデックスを呼び出すとが、私は出力SnargeBarFoo作業

class WorkingController extends FooBase 
{ 
    def beforeInterceptor = { 
     super.beforeInterceptor.action.call() 
     render("Bar") 
    } 

    def index = { 
     render("Foo") 
    } 
} 

を取得しないことをバージョンです。私がBrokenControllerのインデックスを呼び出すと、私はIllegalAccessError

私は、私の質問はここで何が起こっているの詳細については動作していると思いますか?なぜ1つのバージョンで子クラスの親クラスにアクセスできますが、他のバージョンではできませんか?

私が探しているユースケースは、except機能を持つインターセプタ機能を使用できるようになっています。そのためには、インターセプタがマップを使用して実装されているときに、それらを連結できる必要があります。このaboit次

class BrokenController extends FooBase 
{ 
    def beforeInterceptor = [action: {this&childInterceptor()}] 

    def childInterceptor() { 
     super.beforeInterceptor.action.call() 
     render("Bar") 
    } 

    def index = { 
     render("Foo") 
    } 
} 

ドキュメントは述べている:第三のラインをチェック -

+0

この問題の解決方法はありますか? – arvind

答えて

0

this. 

次のコードは動作します
this.& 

の違いがあります。 &

Method Reference  .&  Get a reference to a method, can be useful for creating closures from methods 

だから私はわからないが、私はそれが方法がで呼び出されたスコープを持つ何か藤堂を持っていると思います。たぶん、システムがこのクラスになりクロージャを実行するためにヘルパークラスのいくつかの種類を作成し、 super.beforeInterceptorメソッドを持たない

関連する問題