Reputation: 121
I have successfully generated an XML file using FTL template. Thanks to Debmalya Biswas and his code.
The code saves the file (with specified name) to a set directory on the drive. But I would like to have the file (sorry for the description) handed over by a request, so that the browser saves the file to its download location. Could you please help?
<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>
Upvotes: 1
Views: 54
Reputation: 121
For those seeking an answer, this worked for me:
<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>
I used the sendTextResponse method of ExecutionContext WebFacade.
Upvotes: 1