我在stackoverflow中搜索grailsApplication.controllerClasses
过滤器,然后我遵循正确的答案。
我写这样的代码。
<g:each var="c" in="${grailsApplication.controllerClasses.each{GrailsClassUtils.isClassBelowPackage(it.clazz, ['com.posplus.product']) }.sort{ it.fullName } }">
<li>
<g:link controller="${c.logicalPropertyName}" action="list" data-pjax='#main'>
<g:message code="${c.logicalPropertyName}.label" default="${c.logicalPropertyName}"/>
</g:link>
</li>
</g:each>
它导致错误堆栈
org.codehaus.groovy.grails.web.pages.exceptions.GroovyPagesException: Error applying layout : bootstrap
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
java.lang.Thread.run(Thread.java:680)
root cause
org.codehaus.groovy.grails.web.pages.exceptions.GroovyPagesException: Error processing GroovyPageView: Error executing tag <g:include>: Unable to execute include: Request processing failed; nested exception is org.codehaus.groovy.grails.web.pages.exceptions.GroovyPagesException: Error evaluating expression [grailsApplication.controllerClasses.each{GrailsClassUtils.isClassBelowPackage(it.clazz, ['com.posplus.product']) }.sort{ it.fullName }] on line [13]: null
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
java.lang.Thread.run(Thread.java:680)
root cause
org.codehaus.groovy.grails.web.taglib.exceptions.GrailsTagException: Error executing tag <g:include>: Unable to execute include: Request processing failed; nested exception is org.codehaus.groovy.grails.web.pages.exceptions.GroovyPagesException: Error evaluating expression [grailsApplication.controllerClasses.each{GrailsClassUtils.isClassBelowPackage(it.clazz, ['com.posplus.product']) }.sort{ it.fullName }] on line [13]: null
Users_wenhaoliu_Documents_workspace_posplus_grails_app_views_layouts_bootstrap_gsp$_run_closure2.doCall(bootstrap.gsp:13)
Users_wenhaoliu_Documents_workspace_posplus_grails_app_views_layouts_bootstrap_gsp.run(bootstrap.gsp:21)
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
java.lang.Thread.run(Thread.java:680)
root cause
org.codehaus.groovy.grails.web.servlet.mvc.exceptions.ControllerExecutionException: Unable to execute include: Request processing failed; nested exception is org.codehaus.groovy.grails.web.pages.exceptions.GroovyPagesException: Error evaluating expression [grailsApplication.controllerClasses.each{GrailsClassUtils.isClassBelowPackage(it.clazz, ['com.posplus.product']) }.sort{ it.fullName }] on line [13]: null
Users_wenhaoliu_Documents_workspace_posplus_grails_app_views_layouts_bootstrap_gsp$_run_closure2.doCall(bootstrap.gsp:13)
Users_wenhaoliu_Documents_workspace_posplus_grails_app_views_layouts_bootstrap_gsp.run(bootstrap.gsp:21)
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
java.lang.Thread.run(Thread.java:680)
root cause
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.codehaus.groovy.grails.web.pages.exceptions.GroovyPagesException: Error evaluating expression [grailsApplication.controllerClasses.each{GrailsClassUtils.isClassBelowPackage(it.clazz, ['com.posplus.product']) }.sort{ it.fullName }] on line [13]: null
Users_wenhaoliu_Documents_workspace_posplus_grails_app_views_layouts_bootstrap_gsp$_run_closure2.doCall(bootstrap.gsp:13)
Users_wenhaoliu_Documents_workspace_posplus_grails_app_views_layouts_bootstrap_gsp.run(bootstrap.gsp:21)
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
java.lang.Thread.run(Thread.java:680)
root cause
org.codehaus.groovy.grails.web.pages.exceptions.GroovyPagesException: Error evaluating expression [grailsApplication.controllerClasses.each{GrailsClassUtils.isClassBelowPackage(it.clazz, ['com.posplus.product']) }.sort{ it.fullName }] on line [13]: null
Users_wenhaoliu_Documents_workspace_posplus_grails_app_views_includes_subnav_gsp.run(subnav.gsp:13)
Users_wenhaoliu_Documents_workspace_posplus_grails_app_views_layouts_bootstrap_gsp$_run_closure2.doCall(bootstrap.gsp:13)
Users_wenhaoliu_Documents_workspace_posplus_grails_app_views_layouts_bootstrap_gsp.run(bootstrap.gsp:21)
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
java.lang.Thread.run(Thread.java:680)
root cause
java.lang.NullPointerException
Users_wenhaoliu_Documents_workspace_posplus_grails_app_views_includes_subnav_gsp$_run_closure3_closure8.doCall(subnav.gsp:13)
Users_wenhaoliu_Documents_workspace_posplus_grails_app_views_includes_subnav_gsp$_run_closure3.doCall(subnav.gsp:13)
Users_wenhaoliu_Documents_workspace_posplus_grails_app_views_includes_subnav_gsp.run(subnav.gsp:13)
Users_wenhaoliu_Documents_workspace_posplus_grails_app_views_layouts_bootstrap_gsp$_run_closure2.doCall(bootstrap.gsp:13)
Users_wenhaoliu_Documents_workspace_posplus_grails_app_views_layouts_bootstrap_gsp.run(bootstrap.gsp:21)
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
java.lang.Thread.run(Thread.java:680)
但是如果我将代码更改为
<g:each var="c" in="${grailsApplication.controllerClasses.each{GrailsClassUtils.isClassBelowPackage(it.class, ['com.posplus.product']) }.sort{ it.fullName } }">
<li>
<g:link controller="${c.logicalPropertyName}" action="list" data-pjax='#main'>
<g:message code="${c.logicalPropertyName}.label" default="${c.logicalPropertyName}"/>
</g:link>
</li>
</g:each>
它列出了所有控制器。这里有什么问题?