所以我使用 Primefaces 3.0 上传了一个 zip 文件,之后我的 bean 代码解压缩了该文件。primefaces文件上传代码如下:
<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>
上传文件工作正常,我使用标准的 primefaces 展示代码,然后我的代码执行此操作(所有这些代码都在视图范围的 bean 中):
ret = d.unzip(fname, dir+"/");
button2 = false;
'd' 是一个无范围的类。解压缩功能也适用,因为所有文件都在目标目录中解压缩,但是发生了一些事情,即使 button2 设置为 false,我也无法在运行解压缩后在我的界面中单击它。解压如下:
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;
}
}
上传和解压缩一个小文件(3Mb)工作正常,文件解压缩后我可以单击表单中的 b2。但是对于大文件,即使我将 b2 设置为 disabled='true' 并尝试上传和解压缩,在代码解压缩后整个文件 b2 仍然无法在表单中单击。因此,由于没有更好的词,关于解压缩过程的某些内容似乎是“挂起”表单或不使其响应,但我不知道为什么。在表单之外,我还有其他响应式按钮 - 它只是与上传小部件相同的表单内的那个按钮。