grailsviewconvention-over-configur

Grails: How can I change default view location?


I've got controller AdminTagController. By default view will be located in /adminTag folder. Is it possible to change default folder for this controller to /admin/view? I can specify view for each method but it's not cool

Thank you


Solution

  • It's possible to change it with the afterInterceptor of your controller. Check the example:

    def afterInterceptor = { model, modelAndView ->
        println "Current view is ${modelAndView.viewName}"
        if (model.someVar) {
            modelAndView.viewName = "/mycontroller/someotherview"
        }
        println "View is now ${modelAndView.viewName}"
    }
    

    This is applied to all actions of your controller.