This example is enhancing the previous JSF 2 dataTable example, by adding a “delete” function to delete the row in dataTable.
1. Assign a “Delete” link to the end of each row.
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.
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"> <h:column> <f:facet name="header">Action</f:facet> <h:commandLink value="Delete" action="#{order.deleteAction(o)}" /> </h:column>
public String deleteAction(Order order) { orderList.remove(order); return null; }
Example
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.io.Serializable; import java.math.BigDecimal; import java.util.ArrayList; import java.util.Arrays; import javax.faces.bean.ManagedBean; import javax.faces.bean.SessionScoped; @ManagedBean(name="order") @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) { orderList.remove(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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:ui="http://java.sun.com/jsf/facelets" > <h:head> <h:outputStylesheet library="css" name="table-style.css" /> </h:head> <h:body> <h1>JSF 2 dataTable example</h1> <h:form> <h:dataTable value="#{order.orderList}" var="o" styleClass="order-table" headerClass="order-table-header" rowClasses="order-table-odd-row,order-table-even-row" > <h:column> <f:facet name="header">Order No</f:facet> #{o.orderNo} </h:column> <h:column> <f:facet name="header">Product Name</f:facet> #{o.productName} </h:column> <h:column> <f:facet name="header">Price</f:facet> #{o.price} </h:column> <h:column> <f:facet name="header">Quantity</f:facet> #{o.qty} </h:column> <h:column> <f:facet name="header">Action</f:facet> <h:commandLink value="Delete" action="#{order.deleteAction(o)}" /> </h:column> </h:dataTable> </h:form> </h:body> </html>
3. Demo
From top to bottom, shows a row record being deleted.Download Source Code
Download It – JSF-2-DataTable-Delete-Example.zip (10KB)
This comment has been removed by the author.
ReplyDelete
ReplyDeleteشركة مكافحة حشرات بجازان
Our tailoring factory consists of the 50 sewing experts with quality assurance people and some qualified garments engineers along with fashion designers.
ReplyDeletegold shawls and wraps , shawl wholesale online , prom shawl , embroidered pashmina shawl , pashmina shawls manufacturers , shawl fashion , men's pashmina shawls , best pashmina shawls , buy shawl , pashmina shawl in nepal
nike shoes
ReplyDelete100% real jordans for cheap
yeezy shoes
supreme clothing
ultra boost
goyard
yeezys
michael kors outlet
kd 11 shoes
lebron 16
imp sourceimportant site his comment is herego to these guys Get More InfoLearn More
ReplyDeleteen son çıkan perde modelleri
ReplyDeleteSms onay
MOBİL ODEME BOZDURMA
Nftnasilalinir
Ankara evden eve nakliyat
trafik sigortasi
dedektör
WEBSİTE.KURMA
aşk kitapları
Smm Panel
ReplyDeletesmm panel
iş ilanları
instagram takipçi satın al
Hırdavatçı
beyazesyateknikservisi.com.tr
servis
tiktok jeton hilesi
It s a very useful page. Thank you. c03d302a89c8a7de98c94847a6443b01
ReplyDeletedazkiri
sivas
ergene
aglasun
duzkoy
karakoyunlu
eyyubiye
gole
kepsut
Congratulations on your article, it was very helpful and successful. abd1ca9a961d0b4582c68c6964b72a73
ReplyDeletewebsite kurma
website kurma
numara onay
Thank you for your explanation, very good content. 511f82802591bd2477718d9d49b2acdf
ReplyDeletealtın dedektörü
Good content. You write beautiful things.
ReplyDeletehacklink
taksi
vbet
mrbahis
mrbahis
sportsbet
vbet
korsan taksi
hacklink
Good text Write good content success. Thank you
ReplyDeletemobil ödeme bahis
betpark
slot siteleri
kibris bahis siteleri
poker siteleri
tipobet
betmatik
kralbet
sincan
ReplyDeletesakarya
küçükçekmece
kilis
beylikdüzü
5JOS
kütahya
ReplyDeletesivas
trabzon
artvin
hatay
DHQ
bitlis
ReplyDeletekastamonu
artvin
ısparta
hatay
15F48G
عوازل اسطح
ReplyDeleteكوله