Assuming you have a plugin controller named PluginController and an action 'foo' that you want to override, you can subclass the controller:
class MyController extends PluginController {
def foo = {
...
}
}
but you'll need to do some work in UrlMappings:
class UrlMappings {
static mappings = {
"/$controller/$action?/$id?" {
constraints {}
}
"/myController/foo/$id?"(controller: "myController", action: "foo")
"/myController/$action?/$id?"(controller: "pluginController")
"/pluginController/$action?/$id?"(controller: "errors", action: "urlMapping")
"/"(view:"/index")
"500"(view:'/error')
"404"(controller: "errors", action: "notFound")
}
}
and this depends on an ErrorsController:
class ErrorsController {
def notFound = {
log.debug "could not find $request.forwardURI"
}
def urlMapping = {
log.warn "unexpected call to URL-Mapped $request.forwardURI"
render view: 'notFound'
}
}
which renders a 404 page if you call the old "unmapped" controller actions. You'll need to create grails-app/views/errors/notFound.gsp to show an appropriate 404 page.
The first url mapping ensures that your overridden action is called. The 2nd routes everything else to the original controller. And the 3rd sends 404s for direct access.
"404"(view:'/error')
, can I override that with my own "404" mapping, but to an action in a custom controller instead? – Khedive