Invoke PostConstruct
method at Initial requests
. But, when I upload the images, there are multiple call PreDestroy
method.
That's mean, view id of ImageActionBean
has been change for each FileUploadEvent
. As I thought ViewID
does not changed before redirect to another page,
I tried to clear the temp storage of uploaded files.
If I upload three images, invoke PreDestroy
method fourth times. That's why, I get at lease one file.
My Enviroment
- JBoss 7.1.1 Final
- primefaces-4.0-20130910.075046-7
- omnifaces-1.7.jar
- jboss-jsf-api_2.1_spec-2.0.5.Final.jar
Stack Trace :
>>>>> Initialization Finished
>>>>> Destroy Finished
>>>>> Destroy Finished
>>>>> Destroy Finished
>>>>> Destroy Finished
<h:form id="attachmentForm" enctype="multipart/form-data">
<p:fileUpload fileUploadListener="#{ImageActionBean.handleProposalAttachment}"
mode="advanced" multiple="true" sizeLimit="3000000" update="attachmentTable"
allowTypes="/(\.|\/)(gif|jpe?g|png)$/" id="proposalAttachment"/>
</h:form>
@ManagedBean(name = "ImageActionBean")
@ViewScoped <-- org.omnifaces.cdi.ViewScoped
public class ImageActionBean implements Serializable {
private List<String> fileList;
@PostConstruct
public void init() {
fileList = new ArrayList<String>();
System.out.println("Initialization Finished");
}
@PreDestroy
public void destory() {
// clear uploaded file from temp storage
System.out.println("Destroy Finished");
}
public List<String> getFileList() {
return fileList;
}
public void handleProposalAttachment(FileUploadEvent event) {
UploadedFile uploadedFile = event.getFile();
String fileName = uploadedFile.getFileName().replaceAll("\\s", "_");
fileList.add(fileName);
//save uploadedFile to temp storage
}
}