-
FEATURED COMPONENTS
First time here? Check out the FAQ!
I need upload csv files in ZK this is my zul page:
<zk>
<window
apply="org.zkoss.bind.BindComposer"
viewModel="@id('vm') @init('UploadVM')"
title="win"
position="center"
mode="overlapped"
border="normal"
width="300px"
height="200px">
<button
label="upload"
upload="true,maxsize=801192"
onUpload="@command('uploadFile',upload=event)"
autodisable="self" />
</window>
</zk>
And my java page:
public class UploadVM {
private Media media;
public Media getMedia(){
return media;
}
@NotifyChange("media")
@Command
public void uploadFile(@ContextParam(ContextType.TRIGGER_EVENT) UploadEvent event) {
media = event.getMedia();
media.getStreamData();
}
But with this simple example i have the following error:
Use getStringData() instead
And i don not know what happen.
Who can help me???
//THE UI COMPONENT.. SHOULD HAVE AN ID
fileupload id="csvUpload" width="110px"
label="Upload csv file" style="font-size:11px"
image="/core/images/csv.png"
//THIS SHOULD BE IN THE ZUL VM TO LISTEN THE EVENT'S..
@AfterCompose
public void afterCompose(@ContextParam(ContextType.VIEW) Component view){
Selectors.wireEventListeners(view, this);
}
//THE METHOD THAT UPLOAD THE FILE SELECTED..
@Listen("onUpload=#csvUpload")
public void upload(UploadEvent event){
String name = 'THE FILE NAME';
String path = 'THE PAT OF THE FILE'; //like this: Sessions.getCurrent().getWebApp() //.getRealPath("/resources/csvFiles/") + "/";
this.uploadFile(path, name, ".csv", event.getMedia().getStreamData());
BindUtils.postNotifyChange(null, null, this, "*");
}
//THE METHOD THAT READ THE FILE
public void uploadFile(String path, String name, String ext,
InputStream file) {
try {
OutputStream out = new java.io.FileOutputStream(path + name + ext);
InputStream in = file;
int read = 0;
byte[] bytes = new byte[1024];
while ((read = in.read(bytes)) != -1) {
out.write(bytes, 0, read);
}
in.close();
out.flush();
out.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
//THIS WORKS FOR ME
See if this zk-upload-image-or-image-binding-in you have to change the Image to CSV in code little bit change.
Asked: 2013-09-25 21:23:45 +0800
Seen: 55 times
Last updated: Sep 30 '13
Editable interface to add users
Notify Form of property change
How many times get method called when i use modelView?
How to bind a Model with a Viewmodel
Using databinding in menupopup
ZK Clustering, Session Replication Question [closed]
Problem binding values to a composite component
How can i load a constant in .zul
set selectedItem of list in viewmodel - cleaner way? [closed]