简体   繁体   English

分页中的 Ajax 事件与 Primefaces 数据表不起作用

[英]Ajax event in pagination with Primefaces dataTable not working

I have a "normal" paging with a dataTable.我有一个带有数据表的“正常”分页。 The first "load" brings in 25 items from the database.第一个“加载”从数据库中引入 25 个项目。 In the ajax "page" event I am bringing the following elements in blocks of 25 items.在 ajax“页面”事件中,我将以下元素放入 25 个项目的块中。 Everything works perfectly with version 5.1 of Primefaces, but in version 5.2 the onPageChange method is not called, in fact paging does nothing.一切都与 Primefaces 5.1 版完美配合,但在 5.2 版中没有调用 onPageChange 方法,实际上分页什么也不做。

If in the ajax event "page" I add process="@this" it does call the bean, but not the specified onPageChange method but a start method marked with the @PostConstruct annotation (in this way the same first 25 items and pagination always shows these items).如果在 ajax 事件“page”中我添加 process="@this" 它确实调用了 bean,但不是指定的 onPageChange 方法,而是一个用 @PostConstruct 注释标记的 start 方法(这样,前 25 个项目和分页总是相同的显示这些项目)。

<p:panel id="..."
        header="..."
        style="..."
        toggleable="true"
        toggleSpeed="200" >
    <p:dataTable var="some_var"
                id="myDataTable"
                widgetVar="pag"
                first="#{[bean].first}" <-- bean attribute
                value="#{[bean].collectionOfObjects}"  <-- loading of the first 25 elements
                rows="20"
                paginator="true"
                paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                emptyMessage="..."
                lazy="true"
                rowIndexVar="rowIndex"
                rowStyleClass="#{(rowIndex mod 2) eq 0? '...' : '...'}">
        <p:ajax event="page"
                listener="#{[bean].onPageChange}"/> <-- load the next 25 items (successively)
        <p:ajax event="sort"
                listener="#{[bean].orderListing}"/>
        <p:column width="..."
                    headerText="..."
                    style="..."
                    sortBy="#{some_var.id}"
                    id="...">
            ...
        </p:column>
        [rest of columns]
    </p:dataTable>
</p:panel>

Back (just as an outline):返回(仅作为大纲):

@PostConstruct
protected void init() {
    ...
    this.collectionOfObjects = new GenericLazyModel<CollectionOfObjects>(...);
}

//Method not called by ajax.
public void onPageChange(PageEvent event) {
    //Next 25 items
    this.collectionOfObjects = new GenericLazyModel<CollectionOfObjects>(...);
}

Versions: primefaces 5.2, jsf-api 2.2.2, jsf-impl 2.2.2 (updating these last two will be very expensive).版本:primefaces 5.2、jsf-api 2.2.2、jsf-impl 2.2.2(更新最后两个将非常昂贵)。

In this post there are several possibilities, but I have not managed to solve the error after reading everything carefully.在这篇文章中有几种可能性,但在仔细阅读所有内容后,我还没有设法解决错误。

commandButton/commandLink/ajax action/listener method not invoked or input value not set/updated commandButton/commandLink/ajax action/listener 方法未调用或输入值未设置/更新

Thank you very much to all!非常感谢大家!

Finally, after several tests, I have updated the version of PF to 5.3 and it has worked.最后,经过多次测试,我将PF的版本更新到了5.3,并且成功了。 The error when updating to this version 5.3 was not from the application itself, it was from the primefaces-extensions library that had to be updated to v4.0.0 (at least).更新到这个版本 5.3 时的错误不是来自应用程序本身,而是来自必须更新到 v4.0.0(至少)的 primefaces-extensions 库。 If anyone has a problem updating the PF library, check the version of primefaces-extensions as well.如果有人在更新 PF 库时遇到问题,请同时检查 primefaces-extensions 的版本。

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

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