I posted this solution before, here is the link: http://www.mail-archive.com/[EMAIL PROTECTED]/msg01288.html
However, I'd like to reiterate the biggest problem I had with this and that is that DisplayTag was NOT respecting the order of the columns in the result set. To be fair, it wasn't DisplayTag that was really at fault. Commons-BeanUtils used a basic Map, and this does NOT guarantee order. As such, I had to modify RowSetDynaClass and DynaBean to use a class that supported my insertion order (specifically, I am using Commons-Collection SequencedHashMap).
Here is a small example.
Dennis
--- (viewDisplayTag.jsp) ---
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/displaytag-11.tld" prefix="display" %>
<%@ page import="org.apache.commons.beanutils.RowSetDynaClass,
java.sql.ResultSet,
java.sql.Statement,
java.sql.Connection,
java.sql.DriverManager,
java.util.List,
com.wachovia.cmg.phoenix.util.PhoenixRowSetDynaClass,
java.util.Iterator,
com.wachovia.cmg.phoenix.util.PhoenixDynaBean,
org.apache.commons.beanutils.DynaProperty,
java.util.ArrayList,
net.sourceforge.jtds.jdbc.Driver"
%>
<%
ArrayList rows = null;
// Get connection
DriverManager.registerDriver(new net.sourceforge.jtds.jdbc.Driver());
// URI for the Sql Server jdbc driver
Connection conn = DriverManager.getConnection(YOUR_CONNECTION_STRING);
Statement stmt = null;
ResultSet rs = null;
try {
// Create the statement object
stmt = conn.createStatement();
// Execute the query and get the resultSet
rs = stmt.executeQuery("SELECT * from foo");
// Transform the resultSet to a "disconnected" set of DynaBeans
PhoenixRowSetDynaClass resultSet = new PhoenixRowSetDynaClass(rs, false);
// Transform the DynaBeans to a list object
rows = (ArrayList)resultSet.getRows();
request.setAttribute("rows", rows);
stmt.close();
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
// Get the headers from the resultset
Iterator iterator = rows.iterator();
if (iterator.hasNext()) {
PhoenixDynaBean bean = (PhoenixDynaBean)iterator.next();
PhoenixRowSetDynaClass clazz = (PhoenixRowSetDynaClass)bean.getDynaClass();
DynaProperty[] properties = clazz.getDynaProperties();
request.setAttribute("rowHeaders", properties);
}
%>
<html:html>
<head>
<title>Ad-HocQuery results</title>
<link rel="stylesheet" href="" type="text/css" media="screen, print" />
<script language="_javascript_" type="text/_javascript_" src="">
</head>
<body>
<table>
<%-- Get the nd the resultSetHeaders --%>
<bean:define id="resultSetRowHeaders" name="rowHeaders" scope="request"/>
<%-- Get the resultSet --%>
<%-- Display the Data. NOTE: The order of the output is EXACTLY that of the order of the columns on the resultSet --%>
<display:table name="rows" id="row" export="true" >
<logic:iterate id="resultSetRowHeader" name="resultSetRowHeaders">
<bean:define id='columnHeader' name='resultSetRowHeader' property='name' type="java.lang.String"/>
<display:column property="<%=columnHeader%>" sortable="true" headerClass="sortable" nulls="false">
</display:column>
</logic:iterate>
</display:table>
</table>
</body>
</html:html>
- [displaytag-devel] Ad Hoc Query support Matt Dowell
- Re: [displaytag-devel] Ad Hoc Query support David Erickson
- Re: [displaytag-devel] Ad Hoc Query support Matt Dowell
- Re: [displaytag-devel] Ad Hoc Query support DGraham
- Re: [displaytag-devel] Ad Hoc Query suppor... Matt Dowell
- Re: [displaytag-devel] Ad Hoc Query s... DGraham