Murat Derya Özen Murat Derya Özen - 4 months ago 48
Ajax Question

Datatable does not update after successful ajax call

I have a data table. Each row of the table has a

commandButton
called 'Remove', which is supposed to remove that row from the model and the view and perform an update in-place. As a footer, I have another
commandButton
called 'Remove every row'.

The last button works. I click on it, every row is removed from the model (i.e the
ArrayList
containing the elements becomes empty) and the
dataTable
and
footer facet
is re-rendered (or updated) in the view.

On the other hand, when I click a button on one of the rows, to remove it, it partially works. The corresponding element is removed from the model but the view is not updated. That row is still there in the
dataTable
and the
footer facet
hasn't changed.

I have the following piece of code in my
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>


So, what do you think is the problem here?

I'm using JSF 2.0 and Primefaces 3.0

Answer

I recognize this problem form one of our current PF 3.0 pages. It will work if you use update="@form" instead. I haven't really had the time to investigate the real cause so that I can report it to the PF guys, because this problem does not manifest in all pages. Even in the same table, a different button works as intented.

Give it a try:

<p:commandButton update="@form" ... />

Update: coming to think about it, it's maybe related to the presence of process="@this".

Comments