I am using a p:dataTable
to display a list of players. I have a column to delete the player from the database. This column has a p:commandButton
, that triggers a p:confirmDialog
. The confirm dialog button should both exclude the player and refresh the table. The deletion works just fine, but I can't seem to refresh the data table automatically in any way.
The code is something like this:
The .xhtml
:
<h:form id="form" > <p:growl/> <div class="bloco"> <h2>PLAYERS</h2> <p:dataTable value="#{adminPlayersBean.players}" var="p" paginator="true" paginatorAlwaysVisible="true" paginatorPosition="bottom" rows="8"> // some columns <p:column headerText="X"> <p:commandButton action="#{adminPlayersBean.remove(p)}" update="@form" immediate="true" styleClass="ui-button-danger" icon="pi pi-times"> <p:confirm header="Delete player" message="Delete #{p.getNickname()}?" /> </p:commandButton> </p:column> // ... <p:confirmDialog global="true" showEffect="fade" hideEffect="fade" responsive="true" width="430" > <p:commandButton value="✓ Yes" type="button" styleClass="ui-confirmdialog-yes"/> <p:commandButton value="X No" type="button" styleClass="ui-confirmdialog-no" /> </p:confirmDialog> //...
In the bean:
@Named @ViewScoped public class AdminPlayersBean implements Serializable { private List<Player> players; public void remove(Player player) { playerController.remove(player); //deletes the player from DB this.players = playersController.findAll(); //updates the List that fills the dataTable PrimeFaces.current().ajax().update(":form"); }
I've already tried changing the update from the .xhtml to:
update=":form"
update="@form"
- also, added a "table" id to the
p:dataTable
and triedupdate=":form:table"
In the Bean, I've tried:
PrimeFaces.current().ajax().update(":form");
PrimeFaces.current().ajax().update("@form");
- etc
What am I missing?
Thanks!