Rich:file upload - done label problem
vickypotter Nov 16, 2011 5:51 AMHi,
I want to upload file into particular folder.
For example the folder location C:/UploadedFolder/
First i select one text file like 'test1.txt' using rich:fileUpload component
Then i check the file name exsit in UploadedFolder.
If the file not exist, then upload the file into that folder and i want show 'test1.txt' successfully uploaded.
Otherwise i want to show the 'test1.txt' file already exist.
The uploadButtonAction() method called, when i press upload button, checked the file exist or not,
But the doneLabelValue not set in page.
<rich:fileUpload id="fileUpload" binding="#{FileUploadDemo.uploadComponent}" fileUploadListener="#{FileUploadDemo.uploadButtonAction}" maxFilesQuantity="5" immediateUpload="false" acceptedTypes="txt,png,jpeg,gif,pdf,doc" noDuplicate="true" doneLabel=""#{FileUploadDemo.doneLabelValue}" > </rich:fileUpload>
public class FileUploadDemo { private List<UploadItem> uploadItems = new ArrayList<UploadItem>(); private String doneLabelValue; public String uploadButtonAction(UploadEvent event) { uploadItems = event.getUploadItems(); FileInputStream fileInputStream = null; for (UploadItem uploadItem : uploadItems) { String uploadedFileName = uploadItem.getFileName(); try { String uploadedPath = "C:/UploadedFolder/"; File destinationFile = new File(uploadedPath + uploadedFileName); if (!destinationFile.exists()) { File file = uploadItem.getFile(); fileInputStream = new FileInputStream(file); byte[] data = new byte[Integer.parseInt("" + file.length())]; fileInputStream.read(data); FileUtils.writeByteArrayToFile(destinationFile, data); doneLabelValue = uploadedFileName + "successfully uploaded"; } else { doneLabelValue = uploadedFileName + "file already exist"; } } catch (Exception exception) { System.out.println("Exception occur while upload file"); } finally { if (fileInputStream != null) { try { fileInputStream.close(); } catch (IOException ex) { System.out.println("Exception occur "); } } } } return ""; } public String getDoneLabelValue() { return doneLabelValue; } public void setDoneLabelValue(String doneLabelValue) { this.doneLabelValue = doneLabelValue; } }
Please help me.
Thanks in advance.