These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]

Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: solution of showing dynamic created table by jsf+hibernate
PostPosted: Mon May 21, 2007 5:56 am 

Joined: Thu May 17, 2007 2:43 am
Posts: 2
I have written about this topic in my blog(http://farmerinchina.blog.sohu.com/46978657.html), and now paste here for some discussion.

In some situation, people need to create tables at runtime, so it is hard to map the table to pojo. In my project, I just need to display the content of new table, and then I use the following solution. But I think it has more meaning than what past here.

<t:dataTable id="recorddata"
<t:columns value="#{tableBean.headerModel}" var="columnHeader">
<f:facet name="header">
<h:outputText value="#{columnHeader.cname}" />
<h:outputText value="#{tableBean.columnValue}" />

Backing Bean:

public class TableBean{

private DataModel recordModel;
private DataModel headerModel;
private int labelIndex = 0;

public DataModel getHeaderModel()
if(headerModel == null)
headerModel =new ListDataModel();
return headerModel;

public DataModel getRecordModel() {
if(recordModel== null)
recordModel=new ListDataModel();
return recordModel;

public String getColumnValue()
if(recordModel == null) recordModel = getRecordModel();
Map map = (Map)recordModel.getRowData();
List list = getColumnHeaderList();
String key = list.get(labelIndex)).toString();
Object o = map.get(key);
if(o == null) o = "";
if(labelIndex == map.size()) labelIndex = 0;
return o.toString();
return null;


public class TableDAO{

/*******Get the content of dynamic created table******/
public List getRecordList(String tablename)
SQLQuery query = session.createSQLQuery("select * from "+tablename);
List list = query.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP)
.list();//transform resultset to map
return list;
/*******Get column header**********/
public List getRecordHeaderList()


I use hibernate-3.2, and myfaces-1.1.5

Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.