UploadEvent
仅在文件上传时发送到Fileupload
组件,但我希望在文件开始上传时注意到。无论如何这样做?
答案 0 :(得分:1)
实施例: -
index.zul
<?page title="Auto Generated index.zul"?>
<window title="Drop here" border="normal" width="100%" height="100%"
apply="org.zkoss.bind.BindComposer"
viewModel="@id('vm') @init('com.demo.DropFileViewModel')">
<dropupload maxsize="5120" detection="none"
onUpload="@command('doUpload')">
</dropupload>
<button label="Download" onClick="@command('doDownload')"></button>
</window>
DropFileViewModel.java
package com.demo;
import org.zkoss.bind.BindContext;
import org.zkoss.bind.annotation.Command;
import org.zkoss.bind.annotation.ContextParam;
import org.zkoss.bind.annotation.ContextType;
import org.zkoss.util.media.Media;
import org.zkoss.zhtml.Filedownload;
import org.zkoss.zk.ui.event.UploadEvent;
import org.zkoss.zul.Messagebox;
public class DropFileViewModel {
Media media;
@Command
public void doUpload(@ContextParam(ContextType.BIND_CONTEXT) BindContext ctx) {
UploadEvent upEvent = null;
Object objUploadEvent = ctx.getTriggerEvent();
if (objUploadEvent != null && (objUploadEvent instanceof UploadEvent)) {
upEvent = (UploadEvent) objUploadEvent;
}
if (upEvent != null) {
media = upEvent.getMedia();
Messagebox.show("File Uploaded: " + media.getName());
}
}
@Command
public void doDownload() {
if (media != null)
Filedownload.save(media);
else
Messagebox.show("First Drop Your File");
}
}