0

upload file using zk + java

asked 2013-10-23 17:44:10 +0800

Zenzip gravatar image Zenzip
13 3

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

delete flag offensive retag edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2013-10-24 01:28:12 +0800

cor3000 gravatar image cor3000
6280 2 7

updated 2013-10-24 01:28:42 +0800

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
link publish delete flag offensive edit
0

answered 2013-10-26 17:57:16 +0800

Zenzip gravatar image Zenzip
13 3

done, thanks for help! :D

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
1 follower

RSS

Stats

Asked: 2013-10-23 17:44:10 +0800

Seen: 105 times

Last updated: Oct 26 '13

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