0

Processing uploaded file in ViewModel

asked 2013-07-17 09:44:49 +0800

Jardo gravatar image Jardo
11 1

Hi, I'm trying to upload a file from client and process it in the ViewModel.

zul file:

<button label="Upload file" upload="true" onClick="@command('importTexts')" />

view model:

@Command
@NotifyChange("importedTexts")
public void importTexts()
{
    Media media = Fileupload.get();

    if ( media == null)
    {
        Messagebox.show("No file selected", "Error", Messagebox.OK, Messagebox.ERROR);
        return;
    }
}

The problem is that command importTexts() gets executed immediately after I click the upload button, and before the actual file selection. Therefore Fileupload.get() returns null. I also tried using <fileupload> with the same result:

<fileupload label="Upload file">
    <attribute name="onUpload">vm.importTexts();</attribute>
</fileupload>

What is the right way to do this? I don't want any logic in my zul file. Thanks for your advice.

delete flag offensive retag edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2013-07-17 10:10:12 +0800

sjoshi gravatar image sjoshi flag of India
3493 1 8
http://zkframeworkhint.bl...

Here you can check the demo sample for same zk-upload-image-or-image-binding-in

link publish delete flag offensive edit
0

answered 2013-07-19 12:06:13 +0800

Jardo gravatar image Jardo
11 1

After some experimenting I've done it like this:

zul file:

<fileupload label="Upload file" onUpload="@command('importTexts',media=event.media)" />

view model:

@Command
@NotifyChange("importedTexts")
public void importTexts(@BindingParam("media") Media media)
{
    ...
}

But thanks for your answer anyway.

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: 2013-07-17 09:44:49 +0800

Seen: 45 times

Last updated: Jul 19 '13

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