在 Grails Web Flow 最终状态下渲染 PDF

发布于 2024-09-24 05:49:28 字数 626 浏览 4 评论 0原文

我正在使用渲染插件从 Web Flow 中生成 PDF。问题是我无法获得最终状态来返回 PDF 响应。如果我调用:

renderPdf(template: "/letter/generate/createpdf", model: [letter: flow.letter], filename: 'doc.pdf')

从我的最终状态操作中,它仍然尝试返回最终状态视图。但是,我可以将其表述为:

createpdf {
    action {
        renderPdf(template: "/letter/generate/createpdf", model: [letter: flow.letter], filename: 'doc.pdf')
        return
    }
    on("success").to "finish"
}

但是,我当然会得到:

java.lang.IllegalStateException: getOutputStream() has already been called for this response

我基本上希望我的最终状态返回 PDF 文件。有什么想法吗?

I am using the Rendering plugin to generate a PDF from within a Web Flow. The problem is that I cannot get my end state to return the PDF response. If I call:

renderPdf(template: "/letter/generate/createpdf", model: [letter: flow.letter], filename: 'doc.pdf')

From within my end state action, it still tries to return an end state view. I can, however, put this in something like:

createpdf {
    action {
        renderPdf(template: "/letter/generate/createpdf", model: [letter: flow.letter], filename: 'doc.pdf')
        return
    }
    on("success").to "finish"
}

But then of course I get a:

java.lang.IllegalStateException: getOutputStream() has already been called for this response

I basically want my end state to return the PDF file. Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你对谁都笑 2024-10-01 05:49:28

我假设如果此功能不在网络流的上下文中,它就可以工作。我还注意到,在网络流的最终状态上,有些事情并不像我预期的那样工作。我不清楚为什么会这样,但是当我遇到这样的情况时,我通常会通过重定向到另一个操作来处​​理它。因此,本质上只需将您的 flow.letter 作为参数传递给 webflow 之外的另一个操作即可;这种方法为我解决了许多与网络流相关的问题。不幸的是,我目前无法访问我的代码,因为我似乎记得在网络流末尾使用重定向时保留在范围内的参数的一些细微差别。如果您遇到问题,请将其发布在这里,我会查看。

I'm assuming this functionality works if it's not within the context of a web flow. I've also noticed that some things don't work quite as I expect on the end state of a web flow. I'm not clear exactly why that is, but when I've encountered situations like this I have typically resorted to handling it with a redirect to another action. So essentially just pass your flow.letter as a param to another action outside of the webflow; that approach has fixed a number of webflow related problems for me. Unfortunately I don't have access to my code at the moment, because I seem to recall some nuances around parameters staying in scope when using a redirect at the end of a webflow. If you run into problems post them here and I'll take a look.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文