我正在使用来自 grails 平台核心的导航 api。我正在尝试获取一个会话变量以用于其中一个链接的标题(一个人的名字)。根据可见性和状态部分中的文档:
The closures receive a delegate which resolves the following standard Grails properties:
grailsApplication
pageScope
session
request
controllerName
actionName
flash
params
这似乎表明我可以在 navigation.groovy 中使用该会话。在我的 navigation.groovy 我有一个菜单定义为:
import grails.util.GrailsWebUtil
import org.codehaus.groovy.grails.plugins.springsecurity.SecurityRequestHolder
import org.codehaus.groovy.grails.plugins.springsecurity.SpringSecurityUtils
import org.springframework.orm.hibernate3.SessionFactoryUtils
navigation = {
def isBF = { ->
SpringSecurityUtils.ifAllGranted('ROLE_BF')
}
def indexTitleName = { ->
return session.id
}
app {
home controller:'birthFamily', action:'contactInfo'
}
birthFamily {
index(titleText:indexTitleName())
}
}
程序将无法启动并生成此错误:
| Error 2013-10-18 08:16:57,286 [localhost-startStop-1] ERROR context.GrailsContextLoader - Error initializing the application: Exception evaluating property 'id' for java.util.ArrayList, Reason: groovy.lang.MissingPropertyException: No such property: id for class: org.grails.plugin.platform.conventions.DSLBlockCommand
Message: Exception evaluating property 'id' for java.util.ArrayList, Reason: groovy.lang.MissingPropertyException: No such property: id for class: org.grails.plugin.platform.conventions.DSLBlockCommand
Line | Method
->> 12 | doCall in NrfaNavigation$_run_closure1_closure3
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 28 | doCall in NrfaNavigation$_run_closure1_closure6
| 53 | __newBlock . . . . . . . . . . . in org.grails.plugin.platform.conventions.StandardDSLDelegate
| 66 | methodMissing in ''
| 25 | doCall . . . . . . . . . . . . . in NrfaNavigation$_run_closure1
| 46 | build in org.grails.plugin.platform.conventions.StandardDSLBuilder
| 31 | evaluate . . . . . . . . . . . . in org.grails.plugin.platform.conventions.DSLEvaluator
| 280 | registerNavigation in org.grails.plugin.platform.navigation.NavigationImpl
如果我将 'session.id' 替换为 'hello world' 一切都很好。