-
FEATURED COMPONENTS
First time here? Check out the FAQ!
I'd like to prompt the user for some input in a confirmation dialog box BEFORE the file dialog popup using the upload="true option on a button.
I'm handling the fileUpload in public void handleUpload(@ContextParam(ContextType.BIND_CONTEXT) BindContext ctx)
But by that point the file chooser dialog has already happened.
If I can't do what I want using the upload="true" on a button, how can I manually call the FileUpload dialog from within my VM ?
Thanks
Hello rickcr,
Please refer to the following tutorial that can be used as a reference:
http://ben-bai.blogspot.gr/2012/04/zk-trigger-upload-button-click-by-click.html
Best Regards,
Darksu
I think there is a general security problem with your question and any AJAX based approach when trying to open file open dialog. e.g. try this example http://zkfiddle.org/sample/70r7fk/1-trigger-file-upload-button
The client side trigger will work, while the server side approach only works in IE, but fails in FF/Chrome. In your case you are using a server side command handler, which can only respond some JS to trigger the upload as a consequence of the user input. However JS executed from an AJAX success handler doesn't have the permissions to open a file upload dialog in most browsers. see here: http://stackoverflow.com/questions/29728705/trigger-click-on-input-file-on-asynchronous-ajax-done
So a robust solution can only be to trigger the upload-click directly in a client side onClick handler, without a server side round trip.
Unfortunately that's a fact, we have to live with. No workaround ... you won't win against browser security measures and trigger the dialog from your view model (server side code). (and if you do, please post a bug to FF/Chrome so they can fix it, I don't know why IE have a weaker implementation though).
So you need to give the user a button or some other element to click in order to open the fileupload. In my example I show how this can be implemented in a simple way, using a client side event listener.
Asked: 2016-03-02 21:24:47 +0800
Seen: 32 times
Last updated: Mar 08 '16