Book Image

Mastering JavaServer Faces 2.2

By : Anghel Leonard
Book Image

Mastering JavaServer Faces 2.2

By: Anghel Leonard

Overview of this book

Table of Contents (20 chapters)
Mastering JavaServer Faces 2.2
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
The JSF Life Cycle
Index

Deleting a table row


Deleting a table row can be easily implemented by performing the following steps:

  1. 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));       
    }
  2. Besides columns containing data, add a new column in the table named Delete. Each row can be a link to the deleteXXX 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...