I am working on a web application project using Tapestry 5 framework/javascript. This application takes few inputs and returns pdf files.
I got a new requirement of disabling the form submit button when the user clicks it. The button should stay disabled till the reports are generated. I am planning to write javascript for disabling the submit button. But how can I reenable the buttons while returning pdf file?
I have gone through Tapestry documentation. As per the doc, the valid return types are "Nothing, String, Class, Page, Link, Stream". If I return a page, I can reenable the submit button. If I return a stream, the user will be able to do开发者_开发知识库wnload the pdf. But I want to do both. Is there any way by which I can return multiple objects (may be one object inside another object). (or) Can someone suggest any solution to this problem?
Thanks
I'm guessing your workflow is that the form submit handler directs to a page which returns a stream (the pdf) in the onActivate method. I'm also guessing your set the response headers so that the file is downloaded rather than opened by the browser.
if you do this, the browser typically creates a 'save file as' dialog and the current page is never navigated away from (does not refresh). you will never receive any callback telling you that a file has been downloaded either.
therefore with the above workflow, you will not be able to re-enable your button as a response to the download initiating or completing. this is because the stream response is nothing but arbitrary binary data and not html/javascript capable of being executed by the browser. you cannot return a mixed response of html/javascript + binary file data.
the best you could achieve would be to disable the button for a period of time, and then re-enable it to prevent double clicking. if you don't want to add too much complexity to your application i recommend this approach.
however, you could change your workflow inserting an extra request-response between your form submission and your download.
i.e. instead of directing straight to the page which returns the stream, you could reload your current page which in turn requests the download:
- your form submission saves your pdf generation parameters to the session and returns response (reloading the page)
- the new page loads along with a meta-refresh or script directive to redirect to the download url
- the download url is called returns the stream response along with the correct headers set so that the user sees the 'save file as' dialog
there are probably other approaches which would achieve your desired functionality too however the pattern will be the same in that you will need an additional request-response between form submission and file download.
ps. this is not really a tapestry problem, you will come across the same issue regardless of framework (unless the framework does something special to handle this case). it is just how http/browser technology works.
精彩评论