[Grails] control中使用模板引擎是否与其他闭包冲突?

tongyi121 2008-11-15
在grails的control中使用模板引擎后如果使用想客户端发送信息的话,就会出出错
代码如下:
def selectInfo = {
        def rdn = params.rdn
        if (rdn) {
            OU ou = OU.getByDn(rdn)
            def engine = new groovy.text.SimpleTemplateEngine()
            def binding = [place:ou.toString(),ou:ou.ou,cn:ou.cn,businessCategory:ou.businessCategory]
            def info= engine.createTemplate(getServletContext().getResource("/template/ouInfo.template")).make(binding)
render(contentType: "text/json") {
                info(info.toString())
            }

                    }else{
            render(contentType: "text/json") {
                info(message(code: "object.exist.false"))
            }
        }
    }

上面的代码我找不到错误的地方,但是运行就是出错,即使修改为render一个与模板无关的值,只要有上面的代码,运行就出错。
解决的方法我是找到了,就是不使用闭包返回值,改为render(text:template.toString(), contentType: 'text/plain')就可以,但是还是不明白上面的代码错在哪里?
出错的信息如下:
[46719] errors.GrailsExceptionResolver groovy.lang.MissingMethodException: No signature of method: groovy.text.SimpleTemplateEngine$SimpleTemplate$1.call() is applicable for argument types: (java.lang.String) values: {"组织代号:  test<br>\n组织名称:  test<br>\n组织类型:  公司\n"}
org.codehaus.groovy.runtime.InvokerInvocationException: groovy.lang.MissingMethodException: No signature of method: groovy.text.SimpleTemplateEngine$SimpleTemplate$1.call() is applicable for argument types: (java.lang.String) values: {"组织代号:  test<br>\n组织名称:  test<br>\n组织类型:  公司\n"}
        at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:92)
        at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:230)
        at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:912)
        at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:946)
        at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:756)
        at groovy.lang.Closure.call(Closure.java:292)
        at groovy.lang.Closure.call(Closure.java:287)
        at org.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsControllerHelper.handleAction(SimpleGrailsControllerHelper.java:503)
        at org.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsControllerHelper.executeAction(SimpleGrailsControllerHelper.java:394)
        at org.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsControllerHelper.handleURI(SimpleGrailsControllerHelper.java:233)
        at org.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsControllerHelper.handleURI(SimpleGrailsControllerHelper.java:154)
        at org.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsController.handleRequest(SimpleGrailsController.java:88)
        at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
        at org.codehaus.groovy.grails.web.servlet.GrailsDispatcherServlet.doDispatch(GrailsDispatcherServlet.java:260)
        at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:809)
        at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:571)
        at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:511)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
        at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
        at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1098)
        at org.codehaus.groovy.grails.web.servlet.filter.GrailsReloadServletFilter.doFilterInternal(GrailsReloadServletFilter.java:112)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
        at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1089)
        at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:365)
        at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
        at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
        at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:712)
        at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
        at org.mortbay.jetty.servlet.Dispatcher.forward(Dispatcher.java:268)
        at org.mortbay.jetty.servlet.Dispatcher.forward(Dispatcher.java:126)
        at org.codehaus.groovy.grails.web.util.WebUtils.forwardRequestForUrlMappingInfo(WebUtils.java:202)
        at org.codehaus.groovy.grails.web.util.WebUtils.forwardRequestForUrlMappingInfo(WebUtils.java:189)
        at org.codehaus.groovy.grails.web.mapping.filter.UrlMappingsFilter.doFilterInternal(UrlMappingsFilter.java:117)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
        at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1089)
        at org.codehaus.groovy.grails.web.sitemesh.GrailsPageFilter.parsePage(GrailsPageFilter.java:123)
        at org.codehaus.groovy.grails.web.sitemesh.GrailsPageFilter.doFilter(GrailsPageFilter.java:86)
        at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1089)
        at org.codehaus.groovy.grails.web.servlet.mvc.GrailsWebRequestFilter.doFilterInternal(GrailsWebRequestFilter.java:65)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
        at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1089)
        at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:96)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
        at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:236)
        at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
        at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1089)
        at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:365)
        at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
        at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
        at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:712)
        at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
        at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:139)
        at org.mortbay.jetty.Server.handle(Server.java:295)
        at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:503)
        at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:841)
        at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:639)
        at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:210)
        at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:379)
        at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:361)
        at org.mortbay.thread.BoundedThreadPool$PoolThread.run(BoundedThreadPool.java:442)
Caused by: groovy.lang.MissingMethodException: No signature of method: groovy.text.SimpleTemplateEngine$SimpleTemplate$1.call() is applicable for argument types: (java.lang.String) values: {"组织代号:  test<br>\n组织名称:  test<br>\n组织类型:  公司\n"}
        at OUController$_closure10_closure29.doCall(OUController:170)
        at OUController$_closure10_closure29.doCall(OUController)
        at OUController$_closure10.doCall(OUController:169)
        at OUController$_closure10.doCall(OUController)

令狐虫 2008-11-15
render(contentType: "text/json") {  
       info(info.toString())  
}  
info改为其它名字,不能和你上面的
def info= engine.createTemplate
一样
tongyi121 2008-11-15
还真没注意,谢谢提醒
Global site tag (gtag.js) - Google Analytics