0

UploadEvent仅在文件上传时发送到Fileupload组件,但我希望在文件开始上传时引起注意。反正有这样做吗?

4

1 回答 1

1

例子:-

索引.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");

    }
}
于 2013-10-27T13:25:28.053 回答