[英]Datatable does not update after successful ajax call
我有一個數據表。 該表的每一行都有一個名為“Remove”的commandButton
,它應該從模型和視圖中刪除該行並就地執行更新。 作為頁腳,我有另一個名為'刪除每一行'的 commandButton
。
最后一個按鈕有效。 我點擊它,每一行都從模型中刪除(即包含元素的ArrayList
變為空),並在視圖中重新呈現(或更新) dataTable
和footer facet
。
另一方面,當我單擊其中一行上的按鈕時,為了將其刪除,它會部分起作用。 從模型中刪除相應的元素,但不更新視圖。 該行仍然存在於dataTable
,並且footer facet
沒有更改。
我在users.xhtml
有以下代碼。
<f:metadata>
<f:viewParam name="id" value="#{users.id}" />
<f:event type="preRenderView" listener="#{users.init}" />
</f:metadata>
...
<h:form id="usersForm">
<p:outputPanel>
<p:dataTable id="userTable" value="#{users.user.friendList}" var="friend">
<p:column>
<h:outputText value="#{friend.name}" />
</p:column>
<p:column>
<p:commandButton action="#{users.user.removeFriend(friend)}"
ajax="true"
update="userTable somethingElse" process="@this"
onerror="errorDialog.show();"
icon="ui-icon-delete"
title="delete user">
</p:commandButton>
</p:column>
<f:facet id="somethingElse" name="footer">
aye: ${users.user.xxx}
</f:facet>
</p:dataTable>
</p:outputPanel>
<p:commandButton action="#{users.user.removeAllFriends()}" ajax="true"
update="userTable somethingElse"
process="@this"
icon="ui-icon-close"
value="delete all friends?">
</p:commandButton>
</h:form>
那么,您認為這里的問題是什么?
我正在使用JSF 2.0和Primefaces 3.0
我從當前的PF 3.0頁面中認識到這個問題。 如果您使用update="@form"
,它將起作用。 我沒有真正的時間來調查真正的原因,以便我可以向PF人員報告,因為這個問題並沒有在所有頁面中出現。 即使在同一張桌子中,一個不同的按鈕也可以用作。
試試看:
<p:commandButton update="@form" ... />
更新 :想想它,它可能與process="@this"
的存在有關。
您可能正在使用Primefaces 2.2.1,因為這似乎是由於Primefaces dataTable組件的常見錯誤。 基本上發生的是,從dataTable的元素內部發生的ajax回發不會導致dataTable中元素的部分頁面更新。
最簡單的解決方法是從dataTable外部的按鈕調用回發,其唯一目的是簡單地部分頁面更新dataTable。 這不是最有效的解決方案,因為它會產生兩個回發,但它確實有效。
見我以前回答這個問題, 在這里
如果要使用服務器ID來更新組件(例如userTable
, somethingElse
,...),則這些組件需要與觸發更新的組件(例如,按鈕)位於同一命名容器中。 否則,您需要在update屬性中使用這樣的表達式: update=":usersForm:userTable"
。
主要問題是識別命名容器。 外部按鈕確實有效,因為它與具有ID userTable
的表位於相同的命名容器(表單)中。 小面被更新,因為整個表得到更新,但由於數據表是命名容器本身,它應該是不可能通過只使用更新頁腳update="somethingElse"
的外鍵。
我不確定,為什么內部按鈕不起作用。 我猜數據表中還有另一個命名容器。 如果使用UIComponent實現的findComponent算法找不到組件,PrimeFaces會記錄INFO。 INFO: Cannot find component with identifier "userTable" in view.
這是在jsf 2.0中刷新的解決方案
<p:dataTable id="empl1" var="emp" value="#{dtEmployeeView.employee}" selectionMode="multiple" rowKey="#{emp.id}"
paginator="true" rows="5" tableStyleClass="ui-table-columntoggle">
<p:column width="20" headerText="Id" priority="1">
<h:link value="#{emp.id}" />
</p:column>
<p:column headerText="Employee Name" priority="2">
<h:outputText value="#{emp.pname}" />
</p:column>
</p:dataTable>
<p:commandButton update="form1:empl1" ajax="true" value="Submit" action="#{empService.addEmployee(employee)}" >
<f:event type="preRenderView" listener="#{dtEmployeeView.init()}"/>
</p:commandButton>
我的數據表中有過濾器。 所以我在這里解決了這個問題
oncomplete="PF('myWidgetVar').filter()" and update="@form"
我使用update="@form"
並沒有完全奏效:例如,它沒有更新dataTable中的行數。 我已經擁有的是在更新表單的按鈕上:
process="@this" oncomplete="updateRC();"
然后就在我的下面:
<p:remoteCommand name="updateRC" process="@this" update="@form" />
我為修復行更新問題所做的是將一個styleClass添加到dataTable,例如“myTable”,然后在上面的remoteCommand中為該類添加一個jQuery選擇器,例如:
<p:remoteCommand name="updateRC" process="@this" update="@form @(.myTable)" />
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.