开发者

How can I replace a scaffolded controller action and still call the original in Grails?

开发者 https://www.devze.com 2023-04-05 21:36 出处:网络
I need to \'override\' a scaffolded action in a controller, do some stuff and then invoke the original. I would prefer to use the dynamically generated method and not have to cut and paste the code.

I need to 'override' a scaffolded action in a controller, do some stuff and then invoke the original. I would prefer to use the dynamically generated method and not have to cut and paste the code.

class AccountController 开发者_开发技巧{
    static scaffold = Account
    def list = {
        // do something
        // invoke "super.list" i.e. the dynamically generated scaffold
    }

Any ideas?


You could consider using an interceptor or a filter instead (why? much cleaner)

Controller Interceptors http://grails.org/doc/latest/guide/6.%20The%20Web%20Layer.html#6.1.5

Filters http://grails.org/doc/latest/guide/6.%20The%20Web%20Layer.html#6.6


Once you've done whatever you need to in your new controller, simply redirect to the original. Something along the lines of:

class NewController
 def doSomethingOriginal = {
    redirect(controller: "scaffoldedcontroller", action: "list", params: params)
 }
}

Hopefully this helps

0

精彩评论

暂无评论...
验证码 换一张
取 消