我使用的是grails平臺核心的導航api。我試圖讓一個會話變量用於其中一個鏈接(一個人的名字)的標題中。根據文檔中的知名度和狀態:在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' 與'你好世界「一切都很好。
您是如何將fullName添加到會話的?你確定它在嗎? – Vinny
即使我嘗試session.id或session.toString(),也會顯示錯誤。會話變量只是不存在。 – spock99