我已使用FTL模板成功生成了一个XML文件。感谢Debmalya Biswas和他的代码。
代码将文件(具有指定名称)保存到驱动器上的设置目录中。但我想要一个请求移交的文件(抱歉描述),以便浏览器将文件保存到其下载位置。你能帮忙吗?
<transition name="generateSEPAXML2">
<actions>
<script>
<![CDATA[
import java.io.*
def screenRenderer = ec.screen.makeRender().rootScreen("component://SimpleScreens/screen/SimpleScreens/Accounting/Payment/PaymentSEPA.xml")
.webappName("webroot").renderMode("csv")
String renderOutput = screenRenderer.render()
String fileName = "platba_" + paymentId + "_SEPA.xml"
Writer writer = new FileWriter(fileName)
writer.write(renderOutput)
writer.close()
]]>
</script>
<!--<service-call name="update#mantle.account.payment.Payment" in-map="[paymentId:paymentId, statusId:'PmntConfirmed']"/>-->
</actions>
<default-response url="."/>
</transition>
答案 0 :(得分:1)
对于那些寻求答案的人来说,这对我有用:
<transition name="generateSEPAXML3">
<actions>
<script>
<![CDATA[
import java.io.*
def screenRenderer = ec.screen.makeRender().rootScreen("component://SimpleScreens/screen/SimpleScreens/Accounting/Payment/PaymentSEPA.xml")
.webappName("webroot").renderMode("csv")
String renderOutput = screenRenderer.render()
ec.web.sendTextResponse(renderOutput, "text/xml", "platba_" + paymentId + "_SEPA.xml")
]]>
</script>
<!--<service-call name="update#mantle.account.payment.Payment" in-map="[paymentId:paymentId, statusId:'PmntConfirmed']"/>-->
</actions>
<default-response type="none"/>
</transition>
我使用了ExecutionContext WebFacade的sendTextResponse方法。