Search for all controllers in the application

How to find all the controllers running in the application?

I am trying to create a menu using YUI where only registered controllers will be displayed. The controller class will create a static list with various properties defining the name, action, etc. (Same as grails-nav plugin).

I want to create a taglib that all controllers can find, determine which ones have this static list, then look at each list and create a menu.

I think I can use ControllerGrailsClass.metaClass.hasProperty to determine if this controller has a static property, but how do I find all the Controller classes to poll?

Thanks in advance

+5
source share
1 answer

GrailsApplication. :

class TestController {

    def grailsApplication // gets injected automatically

    def test = {
        grailsApplication.controllerClasses.each { controllerArtefact ->
            def controllerClass = controllerArtefact.getClazz()
            println "$controllerArtefact, $controllerClass"
        }
    }
}

, grails :

import org.codehaus.groovy.grails.commons.ApplicationHolder

def grailsApplication = ApplicationHolder.application
+9

All Articles