This example is enhancing the previous JSF 2 dataTable example, by adding a “delete” function to delete the row in dataTable.

Delete Concept

The overall concept is quite simple :

1. Assign a “Delete” link to the end of each row.

<h:dataTable value="#{order.orderList}" var="o">

    <f:facet name="header">Action</f:facet>
    <h:commandLink value="Delete" action="#{order.deleteAction(o)}" />

2. If “Delete” link is clicked, pass the current row object into the deleteAction(). In deleteAction() method, just removes the current row object from the “list” and return back to the current page.

public String deleteAction(Order order) {
	return null;


A JSF 2.0 example to implement the above concept to delete row in dataTable.

1. Managed Bean

A managed bean named “order”, self-explanatory.

package com.mkyong;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
public class OrderBean implements Serializable{

	private static final long serialVersionUID = 1L;

	private static final ArrayList<Order> orderList = 
		new ArrayList<Order>(Arrays.asList(
		new Order("A0001", "Intel CPU", 
				new BigDecimal("700.00"), 1),
		new Order("A0002", "Harddisk 10TB", 
				new BigDecimal("500.00"), 2),
		new Order("A0003", "Dell Laptop", 
				new BigDecimal("11600.00"), 8),
		new Order("A0004", "Samsung LCD", 
				new BigDecimal("5200.00"), 3),
		new Order("A0005", "A4Tech Mouse", 
				new BigDecimal("100.00"), 10)
	public ArrayList<Order> getOrderList() {
		return orderList;
	public String deleteAction(Order order) {
		return null;
	public static class Order{
		String orderNo;
		String productName;
		BigDecimal price;
		int qty;

		public Order(String orderNo, String productName, 
				BigDecimal price, int qty) {
			this.orderNo = orderNo;
			this.productName = productName;
			this.price = price;
			this.qty = qty;
		//getter and setter methods

2. JSF page

JSF page to display the data with dataTable tag, and create a “delete” link to delete the row record.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
<html xmlns=""   
    	<h:outputStylesheet library="css" name="table-style.css"  />
    	<h1>JSF 2 dataTable example</h1>
    		<h:dataTable value="#{order.orderList}" var="o"

    			<f:facet name="header">Order No</f:facet>
    			<f:facet name="header">Product Name</f:facet>
    			<f:facet name="header">Price</f:facet>
    			<f:facet name="header">Quantity</f:facet>
    			<f:facet name="header">Action</f:facet>
    			<h:commandLink value="Delete" 
                                action="#{order.deleteAction(o)}" />


3. Demo

From top to bottom, shows a row record being deleted.


Download Source Code

Download It – (10KB)