Revision history [back]

click to hide/show revision 1
initial version

answered 2013-02-22 17:34:16 +0800

sjoshi gravatar image sjoshi flag of India

http://zkframeworkhint.bl...

See this example ...

<zk>
    <zscript deferred="true"><![CDATA[
    import org.zkoss.util.media.Media;

    Executions.getCurrent().getDesktop().setAttribute(
            "org.zkoss.zul.Fileupload.target", uploadBtn);

    public void processMedia(Media[] media) {
        if (media != null) {
            for (int i = 0; i < media.length; i++) {
                if (media[i] instanceof org.zkoss.image.Image) {
                    image.setContent(media[i]);
                } else {
                    Messagebox.show("Not an image: " + media[i], "Error",
                            Messagebox.OK, Messagebox.ERROR);
                    break; //not to show too many errors
                }
            }
        }
    }
]]></zscript>
    <vbox>
        <button id="uploadBtn" label="Upload"
            onUpload="processMedia(event.getMedias());"
            onClick="Fileupload.get(-1);" />
        <image id="image" />
    </vbox>
</zk>

It Is showing how can you capture event of file upload you are doing wrong you have to pass event in method .

See this example ...

<zk>
    <zscript deferred="true"><![CDATA[
    import org.zkoss.util.media.Media;

    Executions.getCurrent().getDesktop().setAttribute(
            "org.zkoss.zul.Fileupload.target", uploadBtn);

    public void processMedia(Media[] media) {
        if (media != null) {
            for (int i = 0; i < media.length; i++) {
                if (media[i] instanceof org.zkoss.image.Image) {
                    image.setContent(media[i]);
                } else {
                    Messagebox.show("Not an image: " + media[i], "Error",
                            Messagebox.OK, Messagebox.ERROR);
                    break; //not to show too many errors
                }
            }
        }
    }
]]></zscript>
    <vbox>
        <button id="uploadBtn" label="Upload"
            onUpload="processMedia(event.getMedias());"
            onClick="Fileupload.get(-1);" />
        <image id="image" />
    </vbox>
</zk>

It Is showing how can you capture event of file upload you are doing wrong you have to pass event in method .

In Your Zul file you have to add this line

<window apply="org.zkoss.bind.BindComposer"
        viewModel="@id('vm') @init('com.test.MyViewModel')">
<button  upload="true,maxsize=1000000" onUpload="@command('getUploadedFile', media=event.media)">
</windows>

and in your viewModel MyViewModel.java you have to add a new method with @command

@Command
public void getUploadedFile(@BindingParam("media") Media myMedia)    {
          java.io.File myFile = new java.io.File(myMedia.getName());
          Messagebox.show("path"+myFile.getAbsolutePath());

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