更新后 Primefaces 数据表分页不起作用
Primefaces datatable pagination not working after an update
我正在设计一个应用程序,其中某些输入提要是通过 primefaces 数据表输入的。
版本规范:
PrimeFaces-4.0
JSF-2.1.6
面临的问题:
更新数据表后分页中断。看起来在数据表中触发更新事件之前,分页效果很好。映射到此数据表的列表在 "View Scope".
下
请在下面找到我的数据表 XHTML 代码,
<p:dataTable var="profile" value="#{manualNBean.manualNlist}"
rows="10" paginator="true" paginatorPosition="bottom"
rowIndexVar="rowIndex" lazy="true"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="10,50,100,200" id="statustab">
<p:column headerText="S.No">
<p:outputLabel value="#{rowIndex+1}" />
</p:column>
<p:column headerText="Profile ID">
<p:outputLabel value="#{profile.profileID}" />
</p:column>
<p:column headerText="Law Firm Name">
<p:outputLabel value="#{profile.lawFirmName}" />
</p:column>
<p:column headerText="First Name">
<p:outputLabel value="#{profile.firstName}" />
</p:column>
<p:column headerText="Second Name">
<p:outputLabel value="#{profile.secondName}" />
</p:column>
<p:column headerText="Full Name">
<p:outputLabel value="#{profile.fullName}" />
</p:column>
<p:column headerText="Profile Link">
<h:outputLink value="#{profile.profileLink}" target="_blank">#{profile.profileLink}</h:outputLink>
</p:column>
<p:column headerText="PPTS N" id="editNCol">
<p:commandButton icon="ui-icon-pencil" process="@this"
update="statustab" rendered="#{profile.editbuttonRender}"
action="#{manualNBean.turnoffRender}">
<f:setPropertyActionListener value="#{profile}"
target="#{manualNBean.manualNDTO}" />
</p:commandButton>
<p:autoComplete id="manualN" minQueryLength="3"
value="#{profile.manualN}"
style="#{profile.autocompletebuttonRender}"
completeMethod="#{manualNBean.autocompleteN}">
</p:autoComplete>
</p:column>
</p:dataTable>
此处,更新操作是在命令按钮中执行的。即使在执行更新操作后,惰性模型似乎仍然充满了数据库中的记录,但我想知道为什么分页会中断。
注意: 通过向按钮添加 ajax="false" 属性,页面重新加载,现在分页似乎工作正常。然而,这是不可行的,期待用 Ajax.
来控制它
再补充一点,这个数据表只有在单击按钮后才会从数据库中填充信息。
谁能告诉我哪里出错了?
我没有在 p:commandButton
上使用 update
属性,而是从操作方法更新了一行。现在分页似乎没有中断。然后有两个选项,我用了第一个。
为此使用 OmniFaces AJAX 实用程序。
p:commandButton
属性action
中使用的解决方案如下,
public void updateRow(UIData table) {
int index = table.getRowIndex();
Ajax.updateRow(table, index);
}
使用简单的 PrimeFaces 解决方案以搜索表达式框架的形式
documentation and showcase
服务器端方法如下所示:
public void updateRow(UIData table) {
int index = table.getRowIndex();
RequestContext.update(table.getClientId() + ":@row(" + index + ")");
}
我正在设计一个应用程序,其中某些输入提要是通过 primefaces 数据表输入的。
版本规范: PrimeFaces-4.0 JSF-2.1.6
面临的问题: 更新数据表后分页中断。看起来在数据表中触发更新事件之前,分页效果很好。映射到此数据表的列表在 "View Scope".
下请在下面找到我的数据表 XHTML 代码,
<p:dataTable var="profile" value="#{manualNBean.manualNlist}"
rows="10" paginator="true" paginatorPosition="bottom"
rowIndexVar="rowIndex" lazy="true"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="10,50,100,200" id="statustab">
<p:column headerText="S.No">
<p:outputLabel value="#{rowIndex+1}" />
</p:column>
<p:column headerText="Profile ID">
<p:outputLabel value="#{profile.profileID}" />
</p:column>
<p:column headerText="Law Firm Name">
<p:outputLabel value="#{profile.lawFirmName}" />
</p:column>
<p:column headerText="First Name">
<p:outputLabel value="#{profile.firstName}" />
</p:column>
<p:column headerText="Second Name">
<p:outputLabel value="#{profile.secondName}" />
</p:column>
<p:column headerText="Full Name">
<p:outputLabel value="#{profile.fullName}" />
</p:column>
<p:column headerText="Profile Link">
<h:outputLink value="#{profile.profileLink}" target="_blank">#{profile.profileLink}</h:outputLink>
</p:column>
<p:column headerText="PPTS N" id="editNCol">
<p:commandButton icon="ui-icon-pencil" process="@this"
update="statustab" rendered="#{profile.editbuttonRender}"
action="#{manualNBean.turnoffRender}">
<f:setPropertyActionListener value="#{profile}"
target="#{manualNBean.manualNDTO}" />
</p:commandButton>
<p:autoComplete id="manualN" minQueryLength="3"
value="#{profile.manualN}"
style="#{profile.autocompletebuttonRender}"
completeMethod="#{manualNBean.autocompleteN}">
</p:autoComplete>
</p:column>
</p:dataTable>
此处,更新操作是在命令按钮中执行的。即使在执行更新操作后,惰性模型似乎仍然充满了数据库中的记录,但我想知道为什么分页会中断。
注意: 通过向按钮添加 ajax="false" 属性,页面重新加载,现在分页似乎工作正常。然而,这是不可行的,期待用 Ajax.
来控制它再补充一点,这个数据表只有在单击按钮后才会从数据库中填充信息。
谁能告诉我哪里出错了?
我没有在 p:commandButton
上使用 update
属性,而是从操作方法更新了一行。现在分页似乎没有中断。然后有两个选项,我用了第一个。
为此使用 OmniFaces AJAX 实用程序。
p:commandButton
属性action
中使用的解决方案如下,public void updateRow(UIData table) { int index = table.getRowIndex(); Ajax.updateRow(table, index); }
使用简单的 PrimeFaces 解决方案以搜索表达式框架的形式 documentation and showcase
服务器端方法如下所示:
public void updateRow(UIData table) { int index = table.getRowIndex(); RequestContext.update(table.getClientId() + ":@row(" + index + ")"); }