I have a p:fileUpload which works fine. But I need a partial page rendering of a p:datatable after a new file was uploaded. The datatable shows the current files.
The strange this is, once I upload one file, the table is rerendered, showing one record. But the second time the table is not rerendered, ALTHOUGH the code shows there are 2 entries. This is blowing my mind, I have spent the entire day trying to get this working. At the moment I have a workaround using a ui:repeat.
Here is the code
<h:outputLabel value="Files Upload" style="font-weight: bold;" />
<p:fieldset>
<p:fileUpload id="iconUpload" update="@form"
fileUploadListener="#{appCreateController.processUpload}"
image="/resources/gfx/file_browse_normal.png"
allowTypes="*.jpg;*.png;*.gif;*.doc;*.exe;*.msi"
description="Icon">
</p:fileUpload>
</p:fieldset>
<p:message for="iconUpload" />
<p:dataTable var="appFile" id="appFiles"
value="#{appCreateController.uploadedFiles}" rows="10">
<p:column>
<f:facet name="header">
<h:outputText value="Name" />
</f:facet>
<h:outputText value="#{appFile.uploadedFile.fileName}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Content Type" />
</f:facet>
<h:outputText value="#{appFile.uploadedFile.contentType}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="File Type" />
</f:facet>
<h:selectOneMenu value="#{appFile.uploadedFileType}" id="fileType">
<f:selectItems var="uploadedFileType"
value="#{appCreateController.uploadedFileTypes}"
itemLabel="#{uploadedFileType.name}" />
</h:selectOneMenu>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Size" />
</f:facet>
<h:outputText value="#{appFile.size}" />
</p:column>
</p:dataTable>
Backing bean code:
public void processUpload(FileUploadEvent event)
throws AbortProcessingException {
log.debug("Uploading file: " + event.getFile().getFileName());
UploadedFileVO uploadedFileVO = new UploadedFileVO();
uploadedFileVO.setUploadedFile(event.getFile());
uploadedFiles.add(uploadedFileVO);
log.debug("Uploaded file: " + event.getFile().getFileName());
log.debug("file list now contains file : " + uploadedFiles.size());
}
public List<UploadedFileVO> getUploadedFiles() {
log.debug("Getting uploadedFiles. Total == " + uploadedFiles.size());
return uploadedFiles;
}
public UploadedFileType[] getUploadedFileTypes() {
return UploadedFileType.values();
}
Hope anyone knows a solution 🙂
Cheers,
Coen
OK, I tried with 2.2.1 and upgraded for this issue to 3.0.1. The problem still occurred with 3.0.1 but it is fixed now.
Apparently the JSF engine did not see that the contents of the datatable changed because the getter was already called via another method in the backing bean.
I had another method which in its turn called getUploadedFiles() before the xhtml page did, somehow this affected the re-population of the datatable.