Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Won't Fix
-
Affects Version/s: 1.3.3, 1.3.4
-
Fix Version/s: None
-
Component/s: View technologies
-
Labels:None
-
Environment:Windows
Description
I have a header template within my main.gsp layout:
<g:render template="/header"/>
It references a domain class with a child property
<%
def user = User.get(1)
%>
${ user.profile.name }
Where profile belongsTo user and is not null.
If I access this page via a controller, it works fine.
However, when I try to access this page with only an UrlMapping - i.e.
"/"(view:"/index")
I get the following exception:
org.codehaus.groovy.grails.web.taglib.exceptions.GrailsTagException: Error executing tag <g:render>: Error evaluating expression [user.profile.name] on line [8]: could not initialize proxy - no Session at C:/Users/Tomas/work/childTest/grails-app/views/layouts/main.gsp:14 at C__Users_Tomas_work_childTest_grails_app_views_layouts_main_gsp$_run_closure2.doCall(C__Users_Tomas_work_childTest_grails_app_views_layouts_main_gsp:44)
This can be reproduced with the attached project - navigate to http://localhost:8080/childTest
-
Hide
- childTest-bug-report-06092010.zip
- 06/Sep/10 4:14 AM
- 20 kB
- Tomas Lin
-
- grails-app/conf/BootStrap.groovy 0.3 kB
- grails-app/conf/BuildConfig.groovy 1 kB
- grails-app/conf/Config.groovy 3 kB
- grails-app/conf/DataSource.groovy 0.8 kB
- grails-app/conf/UrlMappings.groovy 0.2 kB
- grails-app/conf/spring/resources.groovy 0.0 kB
- grails-app/domain/.../Profile.groovy 0.1 kB
- grails-app/domain/childtest/User.groovy 0.1 kB
- grails-app/i18n/messages.properties 3 kB
- grails-app/i18n/messages_da.properties 3 kB
- grails-app/i18n/messages_de.properties 4 kB
- grails-app/i18n/messages_es.properties 3 kB
- grails-app/i18n/messages_fr.properties 2 kB
- grails-app/i18n/messages_it.properties 2 kB
- grails-app/i18n/messages_ja.properties 2 kB
- grails-app/i18n/messages_nl.properties 3 kB
- grails-app/.../messages_pt_BR.properties 3 kB
- grails-app/.../messages_pt_PT.properties 3 kB
- grails-app/i18n/messages_ru.properties 4 kB
- grails-app/i18n/messages_th.properties 5 kB
- grails-app/.../messages_zh_CN.properties 2 kB
- grails-app/views/_header.gsp 0.1 kB
- grails-app/views/error.gsp 2 kB
- grails-app/views/index.gsp 4 kB
- grails-app/views/layouts/main.gsp 0.8 kB
- test/unit/childtest/ProfileTests.groovy 0.2 kB
- test/unit/childtest/UserTests.groovy 0.2 kB
- application.properties 0.2 kB
Activity
- All
- Comments
- Work Log
- History
- Activity
- Git Commits
Show
Graeme Rocher
added a comment - As burt said, doing this is a GSP is just plain wrong
This is a bug, but scriptlets are evil. Using a taglib doesn't fix the issue (you're still apparently outside of the OSIV and in the SiteMesh filter) but you can wrap in withTransaction:
import childtest.User class SiteTagLib { def userProfileName = { attrs -> User.withTransaction { status -> def user = User.get(attrs.userId) out << user.profile.name } } }