简体   繁体   English

Primefaces fileupload更新属性不会重新呈现数据表

[英]Primefaces fileupload update attribute does not rerender datatable

I am using Primefaces 6.2 with MyFaces 2.2. 我正在将Primefaces 6.2与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. fileUpload组件部分正常工作,调用了listener方法并保存了文件,但update属性不会触发数据表自动重新呈现。 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): 这是侦听器方法(bean已被视域化):

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");

}

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). PrimeFaces fileUpload更新属性按预期方式工作,并且不需要侦听器方法中的额外代码(将组件ID添加到上下文中)。

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. 问题是由于内部错误,Eclipse中的Liberty Profile服务器未更新/发布它的应用程序副本,因此该应用程序与源代码不同步。 Once that was fixed, it worked as expected. 一旦解决该问题,它就会按预期工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM