如何在 e.g. 期间减少 p:ajax 的请求负载p:dataTable 分页 [英] How to decrease request payload of p:ajax during e.g. p:dataTable pagination

查看:18
本文介绍了如何在 e.g. 期间减少 p:ajax 的请求负载p:dataTable 分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 JSF 2.2 和 Primefaces 5.1.有一个可编辑的 primefaces 数据表,启用了分页.

I am using JSF 2.2 with Primefaces 5.1. There is an editable primefaces datatable with pagination enabled.

            <p:dataTable editMode="row" 
                         editable="true" 
                         value="#{usersBean.users}" 
                         var="user" paginator="true" rows="20">

                <p:ajax event="rowEditInit" onstart="handleRowEditInit(event,this);"/>

                <p:column>
                    <p:rowEditor/>
                </p:column>
                <p:column headerText="Real name">
                    <p:cellEditor rendered="true">
                        <f:facet name="input">
                            <p:inputText value="#{user.realName}"/>
      </f:facet>
                            <f:facet name="output">
                                <h:outputText value="#{user.realName}"/>
                            </f:facet>
</p:cellEditor>
                </p:column>
                <p:column headerText="User name">
                    <p:cellEditor>
                        <f:facet name="input">
                            <p:inputText value="#{user.userName}"/>
                        </f:facet>
                        <f:facet name="output">
                            <h:outputText value="#{user.userName}"/>
                        </f:facet>
                    </p:cellEditor>
                </p:column>
            </p:dataTable>

每次更改页面时,数据表都会使用当前页面的所有数据执行 AJAX POST.如下图所示.

Every time the page is changed the datatable does an AJAX POST with all the data of the current page. As you can partly see in the image below.

对于具有大量数据的大表,这会导致大量请求.这不是必须的吧?有没有办法改变这种行为?

For big tables with much data this results in huge requests. This is not neccessary right? Is there a way to change this behavior?

推荐答案

确实,当您以 HTML 格式提交表单时,默认情况下每个 HTML 输入元素都将作为请求参数发送.因此,PrimeFaces ajax 组件提供了 partialSubmit="true" 属性,然后该属性将发送由 process 属性覆盖的 HTML 输入元素,它 默认为 @this 默认为 @form.

Indeed, when you submit a form in HTML, by default every single HTML input element will be sent as request parameter. PrimeFaces ajax components therefore offer the partialSubmit="true" attribute which will then send only the HTML input elements covered by the process attribute, which defaults in <p:ajax> to @this and in <p:commandXxx> to @form.

因此,只需将此添加到数据表中以优化分页性能:

So, just add this to the data table in case to optimize pagination performance:

<p:ajax event="page" partialSubmit="true" />

并将其添加到任何只需要访问数据表中的当前行(例如在对话框中显示)以优化动作处理性能的命令按钮:

And add this to any command button which only needs to access the current row in the data table (e.g. to show it in a dialog) to optimize action processing performance:

<p:commandButton ... process="@this" partialSubmit="true" />

您也可以通过以下 web.xml 中的上下文参数全局配置它:

You can also configure it globally via below context param in web.xml:

<context-param>
    <param-name>primefaces.SUBMIT</param-name>
    <param-value>partial</param-value>
</context-param>

然后对于您确实需要完整提交的情况,请明确使用partialSubmit="false".

And then for cases where you actually need a full submit, explicitly use partialSubmit="false".

这篇关于如何在 e.g. 期间减少 p:ajax 的请求负载p:dataTable 分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆