0

Prompt user with MessageBox BEFORE fileUpload chooser dialog?

asked 2016-03-02 21:24:47 +0800

rickcr gravatar image rickcr
704 7

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

delete flag offensive retag edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2016-03-02 22:59:53 +0800

Darksu gravatar image Darksu
1991 1 4

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

link publish delete flag offensive edit

Comments

Thanks Darksu, I suppose I could do something like that, but it would seem cleaner to work off a single button click to a single command, even if it means that command has to eventually initiate what upload="true" is doing behind the scenes.

rickcr ( 2016-03-03 00:22:16 +0800 )edit
0

answered 2016-03-08 07:46:53 +0800

cor3000 gravatar image cor3000
6280 2 7

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.

link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
2 followers

RSS

Stats

Asked: 2016-03-02 21:24:47 +0800

Seen: 32 times

Last updated: Mar 08 '16

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More