• April 21, 2016
  • jsf
  • Comments Off on Jsf datatable delete row example

Jsf datatable delete row example

JSF dataTable:

JSF h:dataTable tag is used to render and format HTML table element. It is a rich control tag which can iterate collection or array of values to display data in table format. It also provides attributes to manipulate table data in easy way.


Attribute Description
id id for the tag
dir Direction for text. Valid values are ltr (left to right) and rtl (right to left).
styleClass Cascading stylesheet (CSS) class name
value A component’s value, typically a value binding
bgcolor Background color for the table
border Width of the table’s border
cellpadding Padding around table cells
cellspacing Spacing between table cells
columnClasses Comma-separated list of CSS classes for columns
first Index of the first row shown in the table
footerClass CSS class for the table footer
frame frame surrounding the table should be drawn; valid values: none, above, below, hsides, vsides, lhs, rhs, box, border
headerClass CSS class for the table header
rowClasses Comma-separated list of CSS classes for rows
rules Specification for lines between cells; valid values: groups, rows, columns, all
summary Summary of the table’s purpose and structure used for non-visual feedback
var The variable name created by the data table that represents the current item
title A title used for accessibility. Browsers typically create tooltips for the title’s value
type Type of a link; for example, stylesheet
width Width of an element
onblur Event handler for losing focus
onchange Event handler for value changes
onclick Event handler for Mouse button clicked over the element
ondblclick Event handler for Mouse button double-clicked
onfocus Event handler for element received focus
onkeydown Event handler for Key pressed
onkeypress Event handler for Key pressed and released
onkeyup Event handler for Key released
onmousedown Event handler for Mouse button pressed
onmousemove Event handler for mouse moved
onmouseout Event handler for mouse left
onmouseover Event handler for mouse moved onto
onmouseup Event handler for mouse button released




<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
<html xmlns="http://www.w3.org/1999/xhtml"
	<title>JSF edit data to data table example.</title>
	<h2>JSF edit data to data table example.</h2>
		    value="#{test.students}" var="student">
		<f:facet name="header">Name</f:facet>
		<h:outputText value="#{student.name}" />
		<f:facet name="header">Class</f:facet>
		<h:outputText value="#{student.stuClass}" />
		<f:facet name="header">RollNo</f:facet>
		<h:outputText value="#{student.rollNo}" />
		<f:facet name="header">Age</f:facet>
		<h:outputText value="#{student.age}" />
            <f:facet name="header"></f:facet>
            <h:commandButton value="Delete" 
               action="#{test.deleteStudent}" >        
                  value="#{student}" />


import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
 * Backing bean.
 * @author javawithease
@ManagedBean(name = "test")
public class Test {	
	private Student student;
	private static final List<Student> studentList = 
		new ArrayList<Student>(Arrays.asList(
			new Student("Vivek","MCA 3rd","MCA/07/40",29),
			new Student("Sunil","MCA 3rd","MCA/07/41",33),
			new Student("Bharat","MCA 3rd","MCA/07/42",27),
			new Student("Richi","MCA 3rd","MCA/07/43",28),
			new Student("Sahdev","MCA 3rd","MCA/07/44",28)));
	public List<Student> getStudents(){
		return studentList;
	public String deleteStudent(){
	    return null;
	public Student getStudent() {
		return student;
	public void setStudent(Student student) {
		this.student = student;


 * Managed Bean.
 * @author javawithease
public class Student {
	private String name;
	private String stuClass;
	private String rollNo;
	private int age;	
	public Student(String name, 
			String stuClass, String rollNo, int age) {
		this.age = age;
		this.name = name;
		this.rollNo = rollNo;
		this.stuClass = stuClass;
	public String getName() {
		return name;
	public void setName(String name) {
		this.name = name;
	public String getStuClass() {
		return stuClass;
	public void setStuClass(String stuClass) {
		this.stuClass = stuClass;
	public String getRollNo() {
		return rollNo;
	public void setRollNo(String rollNo) {
		this.rollNo = rollNo;
	public int getAge() {
		return age;
	public void setAge(int age) {
		this.age = age;


<?xml version="1.0" encoding="windows-1252"?>
<faces-config version="2.0" 


<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" 




JSF example44-1
To delete a row, Click on “Delete” button.
JSF example44-2
Download this example.

Comments are closed.