Deleting a table row
Deleting a table row can be easily implemented by performing the following steps:
Define a method in the managed bean that receives information about the row that should be deleted, and remove it from the collection that feeds the table.
For example, for a
Set
collection, the code will be as follows (HashSet<Players>
):public void deleteRowHashSet(Players player) { dataHashSet.remove(player); }
For
Map<String, Players>
, the code will be as follows:public void deleteRowHashMap(Object key) { dataHashMap.remove(String.valueOf(key)); }
Besides columns containing data, add a new column in the table named Delete. Each row can be a link to the
delete
XXX method.For example, we can delete a value from
Set
(HashSet<Players>
), as shown in the following code:<h:dataTable value="#{playersBean.dataHashSet}" var="t"> ... <h:column> <f:facet name="header">Delete</f:facet> <h:commandLink value="Delete" action="#{playersBean...