简体   繁体   中英

GWT FileUpload OnClick

I'm trying to use a GWT button to call a FileUpload using the .click method. I was struggling with getting code to trigger after a file is selected using this method. I've tried using an addChangeHandler but it doesn't seem to be calling once a file is selected.

Any help would be appreciated,

Thanks!

If you use the lastest GWT 2.8.2, you will use Elemental2 and JsInterop (the correct approach right now; please find an explanation here: https://stackoverflow.com/a/52083441/5394086 ).

Then please find some examples below. An implementation for native browser's API: https://developer.mozilla.org/en-US/docs/Web/API/HTML_Drag_and_Drop_API/File_drag_and_drop . It's a modern one with "drag'n'drop" instead of "click", hopefully you will like it.

The first example uses GXT for the UI, but the upload stuff will be the same for generic GWT, so it's easy to modify the example for your purposes. The animated gif shows how it works. What more, it works without additional effort with drag'n'drop. https://gist.github.com/branflake2267/d424e4a0c0b371e3dd9d15bfd3514429

Another example with JSNI is currently kind of deprecated approach: https://gist.github.com/branflake2267/97266601f0f225ae2a750fc8115dc2c4

Finally a very nice Java8 lambdas and also very compact example using only free libraries, since Elemental2 is a part of the "new GWT" and Elemento is open source ( https://github.com/hal/elemento ): https://gist.github.com/ibaca/a8a84b6e7b63259109fd782d7dbadd8d

I hope you will find it useful.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM