• Post Reply Bookmark Topic Watch Topic
  • New Topic

Reg: generating table columns from multiple objects using h:datatable tag in jsf  RSS feed

vishnu bola
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi ranchers,
iam newbie to JSF and have some issue facing regarding h:table. My requriment is that i need to generate a table in which the column data comes from different objects. Please find below the sample program that i coded. Iam not sure if this the right approach. Please help

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@ taglib prefix="h" uri="http://java.sun.com/jsf/html"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<h:dataTable id="AG"
summary="This table visually organizes information and is used for layout only">
<f:facet name="header"><hutputText value ="Name" /></f:facet>
<hutputText value="#{item.emp.name}"/>
<f:facet name="header"><hutputText value ="Expdate" /></f:facet>
<hutputText value="#{item.product.expDate}"/>



My backing bean:
public class TableController{

private TableData tabledata = new TableData();
private ArrayList<TableData> dataLis = new ArrayList<TableData>();
private ArrayList rawlist = new ArrayList();

public TableController() {


public void populatedatatable(){
for(int i =0;i<rawlist.size();i++){

public ArrayList<TableData> getDataLis(){
return this.dataLis;

public void setDataLis(ArrayList<TableData> dataLis) {
this.dataLis = dataLis;
public TableData getTabledata(){
return this.tabledata;

public void setTabledata(TableData tabledata) {
this.tabledata = tabledata;

My objects:
public class TableData {
public Employee emp=new Employee();
public Product product= new Product();

public TableData(){

public Employee getEmp(){
return this.emp;
public void setEmp(Employee emp){
public Product getProduct(){
return this.product;
public void setProduct(Product product){

public class Employee {
private int id;
private String name;
public Employee(){}
public Employee (int id,String name){
this.id = id;
this.name= name;

public void setId(int id){
this.id =id;

public int getId(){
return this.id;
public void setName(String name){
this.name =name;

public String getName(){
return this.name;



Now the questions i have are
1) The data don't show up in the table. Please let me know if this the right approach or is there any other method to do this task.
2) Do i need to create separate tabledata.java bean or can i have that code in tablecontroller. java class itself?
3) Do i need to declare both tabledata.java and tablecontroller.java as managed beans?
4) Do i need to specify properties for each managed bean?
5) Do i need to have <jsp:useBean> tag for tablecontroller inspite of declaring it as managed bean in JSP?

I really appreciate your help and eagerly waiting for your reply.


  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!