so I upload a zip file using Primefaces 3.0, after which my bean code unzips the file. The primefaces file upload code is below:
<h:form id="step3" enctype="multipart/form-data" >
<p:panel id="p3" header="STEP 2: Upload Data File(s)" visible="#{uploadData.panel2}">
<h:outputText value="Select data files to upload." />
<br />
<br />
<p:fileUpload fileUploadListener="#{uploadData.handleFileUpload}"
id="fu2"
mode="advanced"
update="messages3, b2"
multiple="true"
disabled="#{uploadData.fileupload}" />
<p:growl id="messages3" showDetail="true" />
<br />
<div class="finish_button">
<p:commandLink id="b2" value="." actionListener="#{uploadData.storedetails('add')}" update="messages3, b2, fu2, @form step2:fu1" disabled="#{uploadData.button2}" />
</div>
</p:panel>
</h:form>
Uploading the file works fine, I use the standard primefaces showcase code for that, then my code does this (all this code is in a view scoped bean):
ret = d.unzip(fname, dir+"/");
button2 = false;
'd' is an unscoped class. The unzip function also works as all files are unzipped in the destination directory, but something happens so that even though button2 is set to false I can't click on it in my interface after running unzip. Unzip is below:
public int unzip(String filename, String zipPath) {
try {
ZipFile zipFile = new ZipFile(filename);
Enumeration e = zipFile.entries();
while(e.hasMoreElements()) {
ZipEntry entry = (ZipEntry)e.nextElement();
File destinationFilePath = new File(zipPath,entry.getName());
//create directories if required
destinationFilePath.getParentFile().mkdirs();
//if the entry is directory, leave it. Otherwise extract it
if(entry.isDirectory()) {
continue;
}
else {
System.out.println("Extracting " + destinationFilePath);
//Get the InputStream for current entry of the zip file
BufferedInputStream bis = new BufferedInputStream(zipFile.getInputStream(entry));
int b;
byte buffer[] = new byte[1024];
//read the current entry from the zip file, extract it
//and write the extracted file
FileOutputStream fos = new FileOutputStream(destinationFilePath);
BufferedOutputStream bos = new BufferedOutputStream(fos, 1024);
while ((b = bis.read(buffer, 0, 1024)) != -1) {
bos.write(buffer, 0, b);
}
//flush and close streams
bos.flush();
bos.close();
bis.close();
fos.close();
}
}
zipFile.close();
return 1;
}
catch(IOException e) {
showmessage("Uh oh", "There was a problem unzipping the files: "+e.getMessage());
return -1;
}
}
Uploading and unzipping a small file (3Mb) works fine, I can click b2 in the form after the file is unzipping. But for the large file, even if I set b2 as disabled='true' and try to upload and unzip, after the code unzips the entire file b2 still isn't clickable in the form. So something about the unzipping process seems to be 'hanging' the form or not making it responsive, for lack of a better word, but I have no idea why. Outside the form I have other buttons that are responsive - it's just that button inside the same form as the upload widget.