diff --git a/src/main/groovy/grails/plugin/scaffolding/ScaffoldingGrailsPlugin.groovy b/src/main/groovy/grails/plugin/scaffolding/ScaffoldingGrailsPlugin.groovy index b243deb..46506f4 100644 --- a/src/main/groovy/grails/plugin/scaffolding/ScaffoldingGrailsPlugin.groovy +++ b/src/main/groovy/grails/plugin/scaffolding/ScaffoldingGrailsPlugin.groovy @@ -1,7 +1,8 @@ package grails.plugin.scaffolding import grails.plugins.* -import org.grails.web.servlet.view.GroovyPageViewResolver +import grails.util.Environment +import grails.util.Metadata class ScaffoldingGrailsPlugin extends Plugin { @@ -38,10 +39,14 @@ Plugin that generates scaffolded controllers and views for a Grails application. @Override Closure doWithSpring() { {-> + Environment env = Environment.current + boolean reloadEnabled = env.isReloadEnabled() || (Metadata.getCurrent().isDevelopmentEnvironmentAvailable() && env == Environment.DEVELOPMENT) + // Configure a Spring MVC view resolver jspViewResolver(ScaffoldingViewResolver) { bean -> bean.lazyInit = true bean.parent = "abstractViewResolver" + enableReload = reloadEnabled } }} } diff --git a/src/main/groovy/grails/plugin/scaffolding/ScaffoldingViewResolver.groovy b/src/main/groovy/grails/plugin/scaffolding/ScaffoldingViewResolver.groovy index 823fd65..62b2d4e 100644 --- a/src/main/groovy/grails/plugin/scaffolding/ScaffoldingViewResolver.groovy +++ b/src/main/groovy/grails/plugin/scaffolding/ScaffoldingViewResolver.groovy @@ -60,6 +60,10 @@ class ScaffoldingViewResolver extends GroovyPageViewResolver implements Resource ResourceLoader resourceLoader protected Map generatedViewCache = new ConcurrentHashMap<>() + protected boolean enableReload = false + void setEnableReload(boolean enableReload) { + this.enableReload = enableReload + } protected String buildCacheKey(String viewName) { String viewCacheKey = groovyPageLocator.resolveViewFormat(viewName) @@ -100,7 +104,7 @@ class ScaffoldingViewResolver extends GroovyPageViewResolver implements Resource def view = super.loadView(viewName, locale) if (view == null) { String cacheKey = buildCacheKey(viewName) - view = generatedViewCache.get(cacheKey) + view = enableReload? null : generatedViewCache.get(cacheKey) if (view != null) { return view } else { @@ -130,7 +134,7 @@ class ScaffoldingViewResolver extends GroovyPageViewResolver implements Resource def contents = new FastStringWriter() t.make(model.asMap()).writeTo(contents) - def template = templateEngine.createTemplate(new ByteArrayResource(contents.toString().getBytes(templateEngine.gspEncoding), "view:$cacheKey")) + def template = templateEngine.createTemplate(new ByteArrayResource(contents.toString().getBytes(templateEngine.gspEncoding), "view:$cacheKey"), !enableReload) view = new GroovyPageView() view.setServletContext(getServletContext()) view.setTemplate(template)