How to add a progress listener to t:inputfileupload?
so far my attempt
here is the jsp part
<h:form id="fileUploader" enctype="multipart/form-data" target="upload_target" >
<h:panelGrid columns="4" width="100%">
<t:inputFileUpload id="file" value="#{FIleuploadservlet.uploadedFile}" required="true" />
<h:commandButton value="Submit" actionListener="#{FIleuploadservlet.uploadDirect}" onclick="setFormAction();" />
</h:panelGrid>
managed bean...
public void uploadDirect(ActionEvent ae)
{
HttpServletRequest request=(HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
HttpSession session=request.getSession();
try
{
byte[] data = new byte[(int) uploadedFile.getSize()];
uploadedFile.getInputStream().read(data, 0, (int) uploadedFile.getSize());
System.out.println("savefile===="+uploadedFile.getName());
File file=new File("c:\\file");
if(!file.exists())
{
file.mkdirs();
}
FileOutputStream fileOut = new FileOutputStream("c:\\file\\lantern.avi");
fileOut.write(data, 0, data.length);
fileOut.flush();
fileOut.close();
}catch(Exception e)
开发者_如何转开发 {
e.printStackTrace();
}
}
use richfaces library. Its display is good and have a progress bar.
精彩评论