如在AJAX:如何减少磷请求负载电话号码:dataTable的分​​页 [英] How to decrease request payload of p:ajax during e.g. p:dataTable pagination

查看:168
本文介绍了如在AJAX:如何减少磷请求负载电话号码: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 input元素将被作为请求参数。 PrimeFaces Ajax组件,因此提供 partialSubmit =真正的属性,它会发送涉及的HTML输入元素过程属性,它的默认值在&LT;电话号码:AJAX&GT; @this &LT;电话号码:。commandXxx&GT; @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 =假

这篇关于如在AJAX:如何减少磷请求负载电话号码:dataTable的分​​页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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