Skip to content

Instantly share code, notes, and snippets.

@shenie
Created June 9, 2011 23:52
Show Gist options
  • Save shenie/1018017 to your computer and use it in GitHub Desktop.
Save shenie/1018017 to your computer and use it in GitHub Desktop.
How to use Category in gsp without calling "use" in the .gsp itself
class MyGrailsViewResolver extends GrailsViewResolver {
@Override
protected View loadView(String viewName, Locale locale) {
new MyView(super.loadView(viewName, locale))
}
static class MyView implements View {
def View view
MyView(View view) {
this.view = view
}
String getContentType() {
view.getContentType()
}
void render(Map<String, ?> model, HttpServletRequest request, HttpServletResponse response) {
if (model.categories) {
use(model.remove('categories')) {
view.render model, request, response
}
} else {
view.render model, request, response
}
}
}
}
jspViewResolver(MyGrailsViewResolver) { bean ->
bean.lazyInit = true
viewClass = JstlView
prefix = GrailsApplicationAttributes.PATH_TO_VIEWS
suffix = ".jsp"
templateEngine = ref("groovyPagesTemplateEngine")
if (true || developmentMode) {
resourceLoader = ref("groovyPageResourceLoader")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment