-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hello everyone, I would implement in my .java a file uploading function.
Is simple, I've button defined as Button uploadButton = New Button();
but I don't know how: 1- onClick event show up a dialog for choose a file (local filesystem) to upload 2- once selected upload file to specificed folder
I read a lot around about onUpload event but I dont know how to manage in my .java file, I've only found example for .zul file using zk tags... but is not my architecture... I've .java file that do all work, then jsp file that called zk components like grid, listbox etc... etc...
thanks a lot for help
Hi Zenzip,
you can create an UploadButton programmatically like this, and append it to a parent ZK component (e.g. a cell in your listbox, or a div or window...)
This example shows, how to create the button in java, and how to add the "onUpload" event listener, not "onClick"
Button button = new Button();
button.setUpload("true");
button.setLabel("click to upload");
button.addEventListener("onUpload", new EventListener<UploadEvent>() {
@Override
public void onEvent(UploadEvent event) throws Exception {
try {
Media media = event.getMedia();
Clients.showNotification("upload details: " +
" name " + media.getName() +
" size " + (media.isBinary() ? media.getByteData().length :
media.getStringData().length()) +
" type " + media.getContentType());
} catch (Exception e) {
e.printStackTrace();
Messagebox.show("Upload failed");
}
}
});
container.appendChild(button); //your Zk parent component
Asked: 2013-10-23 17:44:10 +0800
Seen: 105 times
Last updated: Oct 26 '13