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

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

问题描述

我正在使用JSF 2.2与Primefaces 5.1。有一个可编辑的原始数据表,分页启用。

 < p:dataTable editMode =row
editable =true
value = #{usersBean.users}
var =userpaginator =truerows =20>

< p:ajax event =rowEditInitonstart =handleRowEditInit(event,this);/>

< p:column>
< p:rowEditor />
< / p:column>
< p:column headerText =实名>
< 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 =用户名>
< 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>

每次更改页面时,datatable都会使用当前页面的所有数据进行AJAX POST。您可以在下面的图片中部分看到。





对于具有大量数据的大表,会产生巨大的请求。这不是必要的吗?有没有办法改变这种行为?

解决方案

确实,当您以HTML格式提交表单时,默认情况下,每一个HTML输入元素将作为请求参数发送。 PrimeFaces ajax组件因此提供 partialSubmit =true属性,然后将 c c c 属性,其默认值为< p:ajax> @this < p:commandXxx> @form



所以,只需将其添加到数据表中,以便优化分页表现:

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

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

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

您还可以通过 web.xml

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

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


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>

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?

解决方案

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" />

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>

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

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

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