Revision history [back]

click to hide/show revision 1
initial version

answered 2013-09-26 15:38:46 +0800

sraul gravatar image sraul flag of Paraguay

//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

//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"

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

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();

out.close();

        } catch (Exception ex) {
         ex.printStackTrace();
     }
 }

//THIS WORKS FOR ME

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