Skip to content

Commit

Permalink
Merge pull request #130 from grails/5.1.x
Browse files Browse the repository at this point in the history
5.1.x
  • Loading branch information
codeconsole authored Sep 14, 2024
2 parents 87a4fb3 + b848b0b commit ab4ff7e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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 {

Expand Down Expand Up @@ -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
}
}}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ class ScaffoldingViewResolver extends GroovyPageViewResolver implements Resource

ResourceLoader resourceLoader
protected Map<String, View> generatedViewCache = new ConcurrentHashMap<>()
protected boolean enableReload = false
void setEnableReload(boolean enableReload) {
this.enableReload = enableReload
}

protected String buildCacheKey(String viewName) {
String viewCacheKey = groovyPageLocator.resolveViewFormat(viewName)
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit ab4ff7e

Please sign in to comment.