0
votes

I am using Primefaces 6.2 with MyFaces 2.2. The fileUpload component is partially working, the listener method is called and the file is saved but the update attribute is not triggering the datatable to rerender automatically. I have to manually refresh the page in order for the uploaded file to display in the datatable.

Here is the view:

<h:form id="uploadForm" enctype="multipart/form-data">

                <p:outputPanel id="uploadPanel" style="float : left; width : 700px; padding-top : 20px">
                        <p:fileUpload id="uploadComponent" fileUploadListener="#{userDocsManagedBean.uploadListener}" mode="advanced" update="userDocsTbl" />
                </p:outputPanel>

                <p:outputPanel id="docsPanel" style="float : left; width : 700px; padding-left : 20px; padding-top : 20px" layout="block">
                    <p:dataTable id="userDocsTbl"
                                value="#{userDocsManagedBean.files}"
                                var="f"
                                rows="10"
                                scrollable="true"
                                scrollWidth="590"
                                scrollHeight="335"
                                style="width:590px; height:350px;"
                                rowHover="true" >

                        <f:facet name="header">
                            <h:outputText value="User Generated Documents" style="font-size: 16px" />
                        </f:facet>

                        <p:column headerText="File Name" styleClass="alignLeft" width="330px" sortBy="#{f.fileName}">
                            <h:outputLink value="#{f.fileName}" onclick="window.open('#{f.fileName}?p1=#{f.path}','pdf').target='_blank';return false;">#{f.fileName}</h:outputLink>
                        </p:column>

                        <p:column headerText="Date Modified" styleClass="alignCenter" width="160px" sortOrder="#{userDocsManagedBean.sortOrder}" sortBy="#{f.dateModified}">
                            <h:outputText value="#{f.dateModified}" />
                        </p:column>

                        <p:column headerText="Size" styleClass="alignCenter" width="80px" sortBy="#{f.size}">
                            <h:outputText value="#{f.size}" />
                        </p:column>

                    </p:dataTable>
                </p:outputPanel>

            </h:form>

Here is the listener method (the bean is viewscoped):

public void uploadListener(FileUploadEvent event) {
    UploadedFile file = event.getFile();
    uploadFile(file);

    FacesContext ctxt = FacesContext.getCurrentInstance();
    Collection<String> ids = ctxt.getPartialViewContext().getRenderIds();
    ids.add("uploadForm:userDocsTbl");

}
1

1 Answers

0
votes

The PrimeFaces fileUpload update attribute is working as expected, and it didn't need the extra code in the listener method (adding the component id to the context).

The issue was the Liberty Profile server in Eclipse was not updating/publishing it's copy of the app due to an internal error so the app was out of sync with the source code. Once that was fixed, it worked as expected.