【问题标题】:How to update other component AFTER filtering lazy dataTable in primefaces如何在primefaces中过滤惰性数据表后更新其他组件
【发布时间】:2014-06-24 12:19:54
【问题描述】:

过滤惰性数据表后是否有可能更新其他组件?

<p:dataTable id="dataTable" value="#{NewsBean.items}" binding="#{NewsBean.items.dataTable}" lazy="true" filteredValue="#{NewsBean.filter}" var="item" paginator="true" rows="10"
            currentPageReportTemplate="(Displaying results {startRecord} - {endRecord} of {totalRecords})"
            paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
            rowsPerPageTemplate="10,20,50,100,200,500,1000" filterEvent="enter">

            ...

            <p:ajax event="filter" update="some_other_component" />

            ...

</p:dataTable>
<p:blockUI block="dataTable" trigger="dataTable" />

具体问题是,过滤器事件在我的数据表完成延迟过滤之前触发,因此其他组件的更新事件将被提前触发。因此该组件无法显示过滤器特定的内容。再次过滤会显示上一步的结果。

我通过 BalusC 找到了一个使用远程命令的解决方案。

<p:ajax event="filter" oncomplete="updateFilterSelection()" />
<p:remoteCommand name="updateFilterSelection" update="some_other_component" />

但使用此解决方案将导致我的 blockUI 无休止地加载。似乎不再触发 oncomplete 事件。

有什么解决办法吗?

我正在使用 primefaces 3.5。

谢谢

编辑:我找到了一个按预期工作的解决方案:

<p:ajax event="filter" listener="#{some_Method}" update="some_other_component" />

some_Method 确实调用了刷新,例如当前视图的重定向。但我敢肯定,这会产生很多开销。

【问题讨论】:

    标签: ajax jsf-2 primefaces datatable lazy-loading


    【解决方案1】:

    我也遇到过类似的问题:

    如何在惰性数据加载后更新用户界面。
    似乎没有 Primefaces 事件。

    这是我的解决方案:

    • 将此添加到您的 LazyDataModel load() 方法中: RequestContext.getCurrentInstance().execute("updateUserInterface()");
    • 在您的视图中创建一个 JavaScript 函数:
      function updateUserInterface() {
      // Commands to update the user interface
      }

    【讨论】:

      【解决方案2】:
      update=":#{p:component('size')}"
      

      这里的size是outputText框的id。

      【讨论】:

        猜你喜欢
        • 2015-04-10
        • 2013-07-30
        • 1970-01-01
        • 1970-01-01
        • 2019-12-19
        • 2016-12-10
        • 2016-03-08
        • 2018-08-24
        • 1970-01-01
        相关资源
        最近更新 更多