2010-07-24 105 views
4

從石英工作渲染GSP我有需要呈現一個GSP石英工作,當我嘗試:Grails中

def g = new org.codehaus.groovy.grails.plugins.web.taglib.ApplicationTagLib() 
def text = g.render(template: "/templates/myTemplate", 
      model: [language: language, 
        product: product]) 

我收到以下異常:

org.quartz.JobExecutionException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request. [See nested exception: java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.] 
    at org.codehaus.groovy.grails.plugins.quartz.GrailsJobFactory$GrailsTaskClassJob.execute(GrailsJobFactory.java:81) 
    at org.quartz.core.JobRunShell.run(JobRunShell.java:202) 
    at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:525) 
Caused by: java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request. 
    at org.springframework.web.context.request.RequestContextHolder.currentRequestAttributes(RequestContextHolder.java:123) 
    at org.springframework.web.context.request.RequestContextHolder$currentRequestAttributes.call(Unknown Source) 
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40) 
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117) 
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:121) 
    at org.codehaus.groovy.grails.web.plugins.support.WebMetaUtils$_registerMethodMissingForTags_closure23.doCall(WebMetaUtils.groovy:248) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
    at java.lang.reflect.Method.invoke(Method.java:597) 
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:88) 
    at org.codehaus.groovy.runtime.metaclass.ClosureMetaMethod.invoke(ClosureMetaMethod.java:80) 
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233) 
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1058) 
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:1070) 
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:886) 
    at groovy.lang.MetaObjectProtocol$invokeMethod.call(Unknown Source) 
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40) 
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117) 
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:133) 
    at org.codehaus.groovy.grails.plugins.web.GroovyPagesGrailsPlugin$_closure4_closure26.doCall(GroovyPagesGrailsPlugin.groovy:311) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
    at java.lang.reflect.Method.invoke(Method.java:597) 
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:88) 
    at org.codehaus.groovy.runtime.metaclass.ClosureMetaMethod.invoke(ClosureMetaMethod.java:80) 
    at groovy.lang.MetaClassImpl.invokeMissingMethod(MetaClassImpl.java:813) 
    at groovy.lang.MetaClassImpl.invokePropertyOrMissing(MetaClassImpl.java:1107) 
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1060) 
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:1070) 
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:886) 
    at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:39) 
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40) 
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117) 
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125) 

使用Grails 1.3.2。關於我能做些什麼來獲得這個工作的任何想法? 編輯:這是目前與Grails的限制http://jira.codehaus.org/browse/GRAILS-3818

回答

2

解決方法可能是使用template-engine插件。

+0

謝謝!這對我很好,我打算添加對請求上下文的嘲諷以使模板在我的應用程序中運行,但有一個我已經可以使用的插件是很棒的。注意,我必須解決這個問題:GrailsTemplateEngineService第45行controllerName應該是pluginName – Peter 2010-07-26 06:34:26

4

由於Grails的2.0.4您可以使用

grails.gsp.PageRenderer.render 

呈現請求上下文之外的模板。

+0

此頁面有一個很好的使用PageRender.render的示例http://mrhaki.blogspot.com.au/2012 /03/grails-goodness-render-gsp-views-and.html – 2016-02-23 23:46:41