-
FEATURED COMPONENTS
First time here? Check out the FAQ!
1 | initial version | |
//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
2 | No.2 Revision |
//THE UI COMPONENT.. SHOULD HAVE AN ID
fileupload id="csvUpload" width="110px"
label="Upload csv file" style="font-size:11px"
//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);
//THIS WORKS FOR ME