alessandro bonvicini wrote:
Quote
Hi all,
Now the problem is how to iterate into the above arraylist[]
with struts tag iterate or something like that.
I don't understand how to do this.
What I found over the internet is very confusing and I am new to struts.
Is there anyone that can send me an help?
Thank
Alex
Try something like this:
package testcoltypes;
import java.awt.*;
import java.awt.event.*;
import com.borland.dx.dataset.*;
import com.borland.dx.sql.dataset.*;
public class DM implements DataModule {
static private DM myDM;
private Database db = new Database();
private QueryDataSet qry2 = new QueryDataSet();
public static DM getDataModule() {
if (myDM == null) {
myDM = new DM();
}
return myDM;
}
public DM() {
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
qry2.setQuery(new com.borland.dx.sql.dataset.QueryDescriptor(database1,
"SELECT MENUS.IDMENU,MENUS.MENUNAME,MENUS.MENUTEXT FROM MENUS", null, true,
Load.ALL));
users.setQuery(new com.borland.dx.sql.dataset.QueryDescriptor(database1,
"SELECT
USERS.IDUSER,USERS.IDROLE,USERS.USERID,USERS.PASSWRD,USERS.USER_NAME,USERS.IDDISTRICT,USERS.ID"
+
"EMPLOYEE,USERS.IDCONTRACTOR,USERS.HOSPITALID FROM USERS", null, true,
Load.ALL));
db.setConnection(new
com.borland.dx.sql.dataset.ConnectionDescriptor("jdbc:firebirdsql:localhost/3050:/opt/example/employees.gdb",
"sysdba", "masterkey", false, "org.firebirdsql.jdbc.FBDriver"));
}
public Database getDatabase1() {
return db;
}
public java.util.Vector getColumns(){
if(qry2.open()==false) {
qry2.open();
}
java.util.Vector vCols= new java.util.Vector();
for (int i=0; i<qry2.getColumnCount(); i++){
vCols.addElement(qry2.getColumn(i).getColumnName());
}
return vCols;
}
public java.util.Vector getRows() {
int colCount=qry2.getColumnCount();
int addTr=0;
java.util.Vector vRows= new java.util.Vector();
DataRow dr= new DataRow(menus);
String[] s=dr.getColumnNames(colCount);
int iRow=1;
for (int i=0; i<qry2.getRowCount(); ++i) {
for (int y=0; y <s.length; ++y) {
Variant v= new Variant();
vRows.addElement("<td style='vertical-align: top;'>");
qry2.getVariant(s[y],i,v);
if(v.getType()==Variant.INT) {
vRows.addElement(""+v.getInt());
}
else if(v.getType()==Variant.FLOAT) {
vRows.addElement(""+v.getFloat());
}
else if (v.getType()==Variant.DOUBLE) {
vRows.addElement(""+v.getDouble());
}
else if(v.getType()==Variant.DATE) {
vRows.addElement(""+v.getDate().toString());
}
else if(v.getType()==Variant.LONG) {
vRows.addElement(""+v.getLong());
}
else if(v.getType()==Variant.STRING) {
vRows.addElement(v.getString());
}
vRows.add("</td>");
if(addTr==colCount-1) {
addTr=0; //start over
vRows.addElement("</tr>");
vRows.addElement("<tr>");
}
else {
++addTr;
}
}
}
return vRows;
}
public com.borland.dx.sql.dataset.QueryDataSet getQry2() {
return qry2;
}
}
A Test.jsp to return data sample
<head>
<title>
Test
</title>
</head>
<body>
<h1>
JBuilder Generated JSP
</h1>
<% Vector vCols=dm.getColumns();
Vector vRows=dm.getRows();
Iterator ic= vCols.iterator();
Iterator ir=vRows.iterator();
%>
<table cellpadding="2" cellspacing="2" border="1"
style="text-align: left; width: 90%; margin-left: auto; margin-right:
auto;">
<tbody>
<tr>
<% while (ic.hasNext()) { %>
<td
style="vertical-align: top; background-color: rgb(102, 102, 102); color:
rgb(255, 255, 255); text-decoration: underline;"><font
size="+1"><%=ic.next()%><br>
</font></td>
<% }%></tr>
<tr>
<!-- now fill in the rows -->
<% while(ir.hasNext()) { %>
<%=ir.next()%>
<% } %>
</tr>
</tbody>
</table>
</body>
</html>