|
|
发表于 2011/7/18 13:54:33
|
显示全部楼层
用以下的代码可以实现,但是有一点不足,就是当数据量比较多的时候,无法按照指定的行数进行分页显示。
先在页面上创建一个advancedTable,名字叫“region5”,即可。
public void processRequest(OAPageContext pageContext, OAWebBean webBean)
{
super.processRequest(pageContext, webBean);
final String CHILD_DATA_LIST = "childDataList";
final String TEXT = "text";
int COLUMN_COUNT = 0;
// write your Personalization SQL in here.
StringBuffer sbfSQL = new StringBuffer(200);
// set title in the advancedTable
sbfSQL.append("SELECT '名' user_name, 'ID' user_id, '開始日' FROM dual \r\n");
sbfSQL.append("UNION ALL \r\n");
sbfSQL.append("SELECT fu.user_name, to_char(fu.user_id), to_char(fu.start_date) FROM fnd_user fu");
ResultSet rs = null;
Statement s = null;
Connection con = pageContext.getApplicationModule(webBean).getOADBTransaction().getJdbcConnection();
try
{
s = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
rs = s.executeQuery(sbfSQL.toString());
ResultSetMetaData rsmd = rs.getMetaData();
COLUMN_COUNT = rsmd.getColumnCount();
rs.last();
int intRowCount = rs.getRow();
rs.first();
// find the advancedTable
OAAdvancedTableBean tableBean = (OAAdvancedTableBean)webBean.findChildRecursive("region5");
tableBean.setViewUsageName("");
for (int i = 1; i <= COLUMN_COUNT; i++)
{
// create a column
OAColumnBean cb = (OAColumnBean)createWebBean(pageContext, COLUMN_BEAN, null, null);
tableBean.addIndexedChild(cb);
// create MessageStyledText
OAMessageStyledTextBean mst = (OAMessageStyledTextBean)createWebBean(pageContext, MESSAGE_STYLED_TEXT_BEAN, null, null);
mst.setTextBinding(TEXT + i);
cb.addIndexedChild(mst);
// create title
OASortableHeaderBean shb = (OASortableHeaderBean)createWebBean(pageContext, SORTABLE_HEADER_BEAN, null, null);
shb.setPrompt(rs.getString(i));
cb.setColumnHeader(shb);
if (i != 1)
{
UINodeList colList = new DataObjectListNodeList(mst, new DataBoundValue(CHILD_DATA_LIST + i));
cb.setIndexedNodeList(colList);
}
}
// get row count;
DictionaryData rowData[] = new DictionaryData[intRowCount - 1];
int intRowLoop = 2;
// loop row
while (rs.next())
{
// setting 1 column cell value
rowData[intRowLoop - 2] = new DictionaryData(TEXT + "1", rs.getString(1));
// setting 2 to N column cell value
DictionaryData otherColumn[] = new DictionaryData[COLUMN_COUNT];
// loop column
for (int j = 2; j <= COLUMN_COUNT; j++)
{
otherColumn[j - 2] = new DictionaryData(TEXT + j, rs.getString(j));
rowData[intRowLoop - 2].put(CHILD_DATA_LIST + j , new ArrayDataSet(otherColumn));
}
intRowLoop++;
}
tableBean.setTableData(new ArrayDataSet(rowData));
}
catch (SQLException se)
{
se.printStackTrace();
}
finally
{
if (s != null)
{
try
{
s.close();
}
catch (SQLException se)
{
se.printStackTrace();
}
}
if (rs != null)
{
try
{
rs.close();
}
catch (SQLException se)
{
se.printStackTrace();
}
}
}
}
|
|