What is the best way of implemting a "Save file" button in IOWA?
I have a form of data that I generate and I want to save it to the
client's machine. Copy and paste, or "Save" from the browser are
not really what I am after here, rather a file transfer kind of option.
Hmmm. Disclaimer: I haven't had enough sleep.
Here's my initial inclination:
-----
<input type="submit" value="Save File" oid="saveFile">
-----
def saveFile
newPage = pageNamed('MyFormData')
newPage.attribute1 = @attribute1
newPage.attribute2 = @attribute2
#
# And so on, setting whatever you need to generate the data that
# you want to save.
#
yield newPage
end
-----
Now, you have a MyFormData.html and a MyFormData.iwa. Do it just like you
would a regular web component, except, of course, this component is intended
to be saved by the browser. You are creating your downloaded file, here.
In MyFormData.iwa:
def setup
req = session.context.request
# Set an appropriate content type.
req.content_type = 'application/octet-stream'
# And set your filename.
req.headers_out['Content-Disposition'] = 'attachment; filename="my.dat"'
end
Your browser should simply download whatever MyFormData generates, now. I
am doing something similar in a few apps in order to generate downloaded CSV
dumps of report contents.
Hope that helps,
Kirk Haines