-
FEATURED COMPONENTS
First time here? Check out the FAQ!
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.
Here you can check the demo sample for same zk-upload-image-or-image-binding-in
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.
Asked: 2013-07-17 09:44:49 +0800
Seen: 45 times
Last updated: Jul 19 '13