Wednesday, July 16, 2008

How to create an Editable data Table Using Seam2.0

here i would like to introduce you the implementation of the Updatable DataTable(An HTML table in Client Side) on change in any of this table field will automatically persist in the Database.
For more details on Seam2.0 Look at
  1. Seam Tutorial
  2. Gavin King Blog
The following is the table we are going to Implement through Seam2.0 Framework.
database Table is

The Table person POJO.

package org.domain.person.model;

// default package
// Generated Jun 26, 2008 4:04:45 PM by Hibernate Tools 3.2.0.CR1

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

import org.jboss.seam.annotations.Name;

* Person generated by hbm2java
@Table(name = "Person", schema = "dbo", catalog = "TEST")
public class Person implements {

    private int id;
    private String firstname;
    private String lastname;
    private String sname;

    public Person() {

    public Person(int id) { = id;

    public Person(int id, String firstname, String lastname, String sname) { = id;
       this.firstname = firstname;
       this.lastname = lastname;
       this.sname = sname;

    @Column(name = "id", unique = true, nullable = false)
    public int getId() {

    public void setId(int id) { = id;

    @Column(name = "firstname", length = 50)
    public String getFirstname() {
       return this.firstname;

    public void setFirstname(String firstname) {
       this.firstname = firstname;

    @Column(name = "lastname", length = 50)
    public String getLastname() {
       return this.lastname;

    public void setLastname(String lastname) {
       this.lastname = lastname;

    @Column(name = "sname", length = 50)
    public String getSname() {
       return this.sname;

    public void setSname(String sname) {
       this.sname = sname;


The Session Bean Handling the Client Table Actions.

package org.domain.person.delegate;

import java.util.ArrayList;
import java.util.List;

import javax.ejb.Remove;
import javax.ejb.Stateful;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.domain.person.model.Person;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Destroy;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Logger;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Out;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.annotations.Synchronized;
import org.jboss.seam.log.Log;

public class TestTable implements TestTableInt{
     @Logger Log log;
     private EntityManager em;

     private static List personList = null;

     @In(create=true) @Out
     private Person person;
     private String myName;

     public void destroy() {

     public void newPerson(){"New person Loading");

     public void save(){

     public List getPersonList() {
         String sql="SELECT T FROM Person T ";
     return personList;

The InterFace

import java.util.List;
import javax.faces.model.SelectItem;

import org.domain.EMSeam2.model.Person;

public interface TestTableInt {
    public void destroy() ;
    public void save();
    public List getPersonList();
    public void newPerson();

Test Table XHTML File :

The XHTML File:

I didnt found any other option to give the file here, you can get it by mailing to


arke56 said...

Hi, I`m from china, I`m sorry, I am no speak english, but I learning jsf richfaces freamwork. I do`t know use of example h:inplaceinput lable!, you website up painted, i do`t understand. can you give me a little about richfaces example? thank you!
my mailbox :

Test said...

Thanks for your email, this article is really helpful.