2010-07-24 52 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