こんにちは、私たちのアプリケーションの一部で、フィルターからコントローラーにデータを渡す必要があります。これは、コントローラーのリクエストオブジェクトとbeforeインターセプターを使用して実行できることを読みました。
いくつかのサンプルコード:
class SomeService {
def doSomething(request, params) {
request.foo = "helloworld"
}
}
class SomeFilter {
def someService
def filters = {
all(controller:'*', action:'*') {
before = {
// service does something and places object in request
// using request.foo = "helloworld"
someService.doSomething(request, params)
}
}
}
}
class SomeController {
def foo
def beforeInterceptor = {
foo = request.foo
}
def index = {
println foo
}
}
これは物事を行うための効率的な方法ですか、それとも他の方法がありますか?