在 Grails Web Flow 最终状态下渲染 PDF
我正在使用渲染插件从 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设如果此功能不在网络流的上下文中,它就可以工作。我还注意到,在网络流的最终状态上,有些事情并不像我预期的那样工作。我不清楚为什么会这样,但是当我遇到这样的情况时,我通常会通过重定向到另一个操作来处理它。因此,本质上只需将您的 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.