0

onUpload not working

asked 2010-05-25 17:19:07 +0000

tapiasnora gravatar image tapiasnora
18 1

I have a problem with the onUpload Event, it is not working at all in my web application
in netbeans, I have the 5.0 zk libraries. This is the code I have in a .zul file:

<window id="winFormularioAgregarAdjunto" border="normal" width="40%" closable="true"
apply="iosframework.web.components.com_contactos_zk.ControladorZK">

<grid>
<columns>
<column />
<column />
<column />
</columns>
<rows>
<row>
<textbox id="path" rows="1" width="85%"/>
<fileupload label="Examinar..." onUpload="upload(event)"/>
<hbox id="pics" />
</row>
</rows>
</grid>
<zscript language="java">
void upload(org.zkoss.zk.ui.event.UploadEvent event) {
org.zkoss.util.media.Media media = event.getMedia();
if (media != null) {
org.zkoss.zul.Image image = new org.zkoss.zul.Image();
image.setContent(media);
image.setParent(pics);
} else {
Messagebox.show("null: " + media, "Error", Messagebox.OK,
Messagebox.ERROR);
}
}
</zscript>

</window>

I have tried this on this site, and it works, I have not idea what is the problem. I also
have the right configurations of spring. Anything else I need to do so it can work?.

Thanks.

delete flag offensive retag edit

1 Reply

Sort by ยป oldest newest

answered 2010-05-25 19:15:42 +0000

fmelossi gravatar image fmelossi
93

The following example works very well, I hope to help you


<button width="80px" label="Upload" upload="true" >
<attribute name="onUpload">{
import java.io.*;
org.zkoss.util.media.Media media = event.getMedia();

if (media instanceof org.zkoss.image.Image) {
OutputStream outputStream = new FileOutputStream("/var/archivos_intranet/NOTICIAS/" + media.getName());
//OutputStream outputStream = new FileOutputStream("C:\\log\\" + media.getName());
rut.setValue(media.getName());
org.zkoss.zul.Image image = new org.zkoss.zul.Image();
image.setContent(media);
image.setWidth("150px");
image.setHeight("150px");
image.setParent(pics);


java.io.InputStream inputStream = media.getStreamData();
byte[] buffer = new byte[1024];
for (int count; (count = inputStream.read(buffer)) != -1;) {
outputStream.write(buffer, 0, count);
}
outputStream.flush();
outputStream.close();
inputStream.close();

} else {
Messagebox.show("Solo Puede cargar imagenes");
break; //not to show too many errors
}
}</attribute>

</button>Cargar Imagen

link publish delete flag offensive edit
Your reply
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

RSS

Stats

Asked: 2010-05-25 17:19:07 +0000

Seen: 1,156 times

Last updated: May 25 '10

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