本文介绍了Grails渲染插件在Grails3.2.4中不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想渲染一个视图到pdf并尝试使用Grails渲染插件2.0.3



我尝试了最简单的gsp文件:

 <!DOCTYPE html PUBLIC -  // W3C // DTD XHTML 1.0 Strict // ENhttp://www.w3 .ORG / TR / XHTML1 / DTD / XHTML1-strict.dtd> 
要更改此许可证标题,请在项目属性中选择许可证标题。
要更改此模板文件,请选择工具|模板
并在编辑器中打开模板。
- >


< html>
< head>
< meta http-equiv =Content-Typecontent =text / html; charset = UTF-8>
< title>样本标题< / title>
< / head>
< body>
< h1>取样线< / h1>
< / body>
< / html>

并在控制器中:

<$ p $ ()
println(>>> Offerheader:+ oh.sawMill)
// render(template:/ offerHeader / Test)
renderPdf(template:/ offerHeader / Test,文件名:offertrapport.pdf)

}

以此结尾:

  2017-04-14 11:26:55.989错误--- [nio-8080-exec-6] ogweb.errors.GrailsExceptionResolver:处理请求时发生NullPointerException:[GET] / offerHeader / report / 15 
Stacktrace如下:

java.lang.reflect.InvocationTargetException:null
at org.grails.core.DefaultGrailsControllerClass $ ReflectionInvoker.invoke(DefaultGrailsControllerClass.java:210)
在org.grails.core.DefaultGrailsControllerClass.invoke(DefaultGrailsControllerClass.java:187)
at org.grails.web.mapping.mvc.UrlMappingsInfoH andlerAdapter.handle(UrlMappingsInfoHandlerAdapter.groovy:90)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963)
at org.springframework.web.servlet.DispatcherServlet.doService( DispatcherServlet.java:897)在org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970

在org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java: 861)
在org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
在org.springframework.boot.web.filter.ApplicationContextHeaderFilter.doFilterInternal(ApplicationContextHeaderFilter.java:55)
在org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:317)
在org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:
在org.springframework.security.web.access.intercep t.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:91)维持在org.springframework.security.web org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:331)

。 access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:115)
at grails.plugin.springsecurity.web.UpdateRequestContextHolderExceptionTranslationFilter.doFilter(UpdateRequestContextHolderExceptionTranslationFilter.groovy:64)
at org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:331)
at grails.plugin.springsecurity.web.filter.GrailsAnonymousAuthenticationFilter.doFilter(GrailsAnonymousAuthenticationFilter.groovy:53)
at org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:331)
at org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter.doFilter(RememberMeAuthenticationFi lter.java:158)
at org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:331)
at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter( SecurityContextHolderAwareRequestFilter.java:169)
at org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:331)
at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter( AbstractAuthenticationProcessingFilter.java:200)
at org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:331)
at grails.plugin.springsecurity.web.authentication.logout.MutableLogoutFilter。 doFilter(MutableLogoutFilter.groovy:62)
at org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:331)
at org.springframework.security.web.context.SecurityContextPersistenc eFilter.doFilter(SecurityContextPersistenceFilter.java:105)
at org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:331)
at grails.plugin.springsecurity.web.SecurityRequestHolderFilter。 doFilter(SecurityRequestHolderFilter.groovy:58)
at org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:331)
at org.springframework.security.web.FilterChainProxy.doFilterInternal( FilterChainProxy.java:214)
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:177)
at org.grails.web.servlet.mvc.GrailsWebRequestFilter.doFilterInternal(GrailsWebRequestFilter。的java:在org.grails.web.filters.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:67 77)

。在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)$ b $ java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPo olExecutor.java:617)
在java.lang.Thread.run(Thread.java:745)
导致:java.lang.NullPointerException:null $ b $在java.beans.Introspector。 getPublicDeclaredMethods(Introspector.java:1337)
在java.beans.Introspector.getTargetMethodInfo(Introspector.java:1197)
在java.beans.Introspector.getBeanInfo(Introspector.java:426)
java.beans.Introspector.getBeanInfo(Introspector.java:173)
at grails.plugins.rendering.document.RenderEnvironment.init(RenderEnvironment.groovy:31)
at grails.plugins.rendering.document .RenderEnvironment.with(RenderEnvironment.groovy:68)
在grails.plugins.rendering.document.RenderEnvironment.with(RenderEnvironment.groovy:60)
在grails.plugins.rendering.document.XhtmlDocumentService.generateXhtml (XhtmlDocumentService.groovy:65)
at grails.plugins.rendering.document.XhtmlDocumentService.createDocument(XhtmlDocumentService.groovy:35)
at grails.plugins.rendering.RenderingSe在grails.plugins.rendering.RenderingService.render(RenderingService.groovy:35)
(在grails.plugins.rendering.RenderingService.render(RenderingService.groovy: 65)
at grails.plugins.rendering.RenderingTrait $ Trait $ Helper.render(RenderingTrait.groovy:66)
at grails.plugins.rendering.RenderingTrait $ Trait $ Helper.renderPdf(RenderingTrait.groovy: 45)
。在com.torntrading.portal.OfferHeaderController $ tt__report(OfferHeaderController.groovy:123)
。在grails.transaction.GrailsTransactionTemplate $ 2.doInTransaction(GrailsTransactionTemplate.groovy:96)
。在有机.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:133)
at grails.transaction.GrailsTransactionTemplate.execute(GrailsTransactionTemplate.groovy:93)
... 37个常用框架省略

我错过了什么?或者是不是可以使用这个版本的grails(3.2.4)?



也许有更好的插件可用?




  依赖关系{
...
runtime'org.springframework:spring-test:4.2.1.RELEASE
}

然后让我们说我们要在点击链接时渲染pdf,所以在gsp中:

 < g:link action =reportparams ='[offerId:$ {offer.id}]'>至PDF< / g:link> 

然后在控制器中:

  def report(){
def offer = Offer.get(params.offerId)
renderPdf(template:offerpdf,model:[offer:offer],filename: offer.pdf)
}

在您的offer views目录中,您将拥有一个模板gsp命名为 _offerpdf.gsp

 <!DOCTYPE html PUBLIC - // W3C // DTD XHTML 1.0 Strict // ENhttp://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\"> 
< html>
< head>
< title>优惠< / title>
< meta http-equiv =Content-Typecontent =text / html; charset = UTF-8/>
< / head>
< body>
< h1>优惠:$ {offer.id}< / h1>
< / body>
< / html>


I want to render a view to pdf and tried using the Grails rendering plugin 2.0.3

I tried the simplest gsp-file to start with:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
  To change this license header, choose License Headers in Project Properties.
  To change this template file, choose Tools | Templates
  and open the template in the editor.
-->

<%@ page contentType="text/html;charset=UTF-8" %>

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Sample title</title>
    </head>
    <body>
        <h1>Sample line</h1>
    </body>
</html>

And in the controller:

    def report() {
        def OfferHeader oh = OfferHeader.get(15)
        println(">>> Offerheader: "+oh.sawMill)
//        render(template: "/offerHeader/Test")
        renderPdf(template: "/offerHeader/Test",  filename: "offertrapport.pdf")

    }

And that ends with:

2017-04-14 11:26:55.989 ERROR --- [nio-8080-exec-6] o.g.web.errors.GrailsExceptionResolver   : NullPointerException occurred when processing request: [GET] /offerHeader/report/15
Stacktrace follows:

java.lang.reflect.InvocationTargetException: null
    at org.grails.core.DefaultGrailsControllerClass$ReflectionInvoker.invoke(DefaultGrailsControllerClass.java:210)
    at org.grails.core.DefaultGrailsControllerClass.invoke(DefaultGrailsControllerClass.java:187)
    at org.grails.web.mapping.mvc.UrlMappingsInfoHandlerAdapter.handle(UrlMappingsInfoHandlerAdapter.groovy:90)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
    at org.springframework.boot.web.filter.ApplicationContextHeaderFilter.doFilterInternal(ApplicationContextHeaderFilter.java:55)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:317)
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:127)
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:91)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
    at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:115)
    at grails.plugin.springsecurity.web.UpdateRequestContextHolderExceptionTranslationFilter.doFilter(UpdateRequestContextHolderExceptionTranslationFilter.groovy:64)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
    at grails.plugin.springsecurity.web.filter.GrailsAnonymousAuthenticationFilter.doFilter(GrailsAnonymousAuthenticationFilter.groovy:53)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
    at org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter.doFilter(RememberMeAuthenticationFilter.java:158)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
    at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:169)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
    at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:200)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
    at grails.plugin.springsecurity.web.authentication.logout.MutableLogoutFilter.doFilter(MutableLogoutFilter.groovy:62)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
    at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:105)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
    at grails.plugin.springsecurity.web.SecurityRequestHolderFilter.doFilter(SecurityRequestHolderFilter.groovy:58)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
    at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:214)
    at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:177)
    at org.grails.web.servlet.mvc.GrailsWebRequestFilter.doFilterInternal(GrailsWebRequestFilter.java:77)
    at org.grails.web.filters.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:67)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NullPointerException: null
    at java.beans.Introspector.getPublicDeclaredMethods(Introspector.java:1337)
    at java.beans.Introspector.getTargetMethodInfo(Introspector.java:1197)
    at java.beans.Introspector.getBeanInfo(Introspector.java:426)
    at java.beans.Introspector.getBeanInfo(Introspector.java:173)
    at grails.plugins.rendering.document.RenderEnvironment.init(RenderEnvironment.groovy:31)
    at grails.plugins.rendering.document.RenderEnvironment.with(RenderEnvironment.groovy:68)
    at grails.plugins.rendering.document.RenderEnvironment.with(RenderEnvironment.groovy:60)
    at grails.plugins.rendering.document.XhtmlDocumentService.generateXhtml(XhtmlDocumentService.groovy:65)
    at grails.plugins.rendering.document.XhtmlDocumentService.createDocument(XhtmlDocumentService.groovy:35)
    at grails.plugins.rendering.RenderingService.render(RenderingService.groovy:36)
    at grails.plugins.rendering.RenderingService.render(RenderingService.groovy:35)
    at grails.plugins.rendering.RenderingService.render(RenderingService.groovy:65)
    at grails.plugins.rendering.RenderingTrait$Trait$Helper.render(RenderingTrait.groovy:66)
    at grails.plugins.rendering.RenderingTrait$Trait$Helper.renderPdf(RenderingTrait.groovy:45)
    at com.torntrading.portal.OfferHeaderController.$tt__report(OfferHeaderController.groovy:123)
    at grails.transaction.GrailsTransactionTemplate$2.doInTransaction(GrailsTransactionTemplate.groovy:96)
    at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:133)
    at grails.transaction.GrailsTransactionTemplate.execute(GrailsTransactionTemplate.groovy:93)
    ... 37 common frames omitted

What am I missing? Or is it not expected to work with this version of grails (3.2.4)?

Maybe there is better plugins to use?

解决方案

First add the following dependency to build.gradle:

dependencies {
    ...
    runtime "org.springframework:spring-test:4.2.1.RELEASE"
}

Then lets say we're going to render the pdf on the click of a link so in gsp:

<g:link action="report" params='[offerId: "${offer.id}"]'>To PDF</g:link>

Then in controller:

def report() {
    def offer = Offer.get( params.offerId )
    renderPdf(template: "offerpdf", model: [offer: offer],  filename: "offer.pdf")
}

In your offer views directory you'd have a template gsp named _offerpdf.gsp

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
    <title>Offer</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<h1>Offer: ${offer.id}</h1>
</body>
</html>

这篇关于Grails渲染插件在Grails3.2.4中不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 22:03