Java bean and ResultSet
Here is how I store the DB ResultSet inside a java bean.
The Problem is when I go to display it using JSTL, i get nothing but a blank HTML page.
public ArrayList getData(String theQuery)
{
ArrayList resultsList =new ArrayList();
try
{
ResultSet rs = aDBBean.getResultSet(theQuery,false);
while (rs.next())
{
aResultBean =new cims.Beans.General.resultsBean();
aResultBean.setBms(rs.getString(1));
aResultBean.setMcc(rs.getString(2));
aResultBean.setHigh_life_limit(rs.getString(3));
aResultBean.setMech_life_limit(rs.getString(4));
aResultBean.setToolside_hdlg_life_limit(rs.getString(5));
aResultBean.setToolside_mech_life_limit(rs.getString(6));
resultsList.add(aResultBean);
}
}
catch(SQLException sqle)
{
System.err.print("SQL ERROR " + sqle);
}
return (resultsList ==null) ?null : resultsList;
}
Am I storing the bean wrong?
But if i store a Map in my List instead of a bean, I can display the data using JSTL.
Map rows =new HashMap();
rows.put("1", rs.getObject(1));
rows.put("2", rs.getObject(2));
rows.put("3", rs.getObject(3));
rows.put("4", rs.getObject(4));
rows.put("5", rs.getObject(5));
rows.put("6", rs.getObject(6));
rows.put("7", rs.getObject(7));
rows.put("8", rs.getObject(8));
rows.put("9", rs.getObject(9));
rows.put("10", rs.getObject(10));
rows.put("11", rs.getObject(11));
Map sortedMap =new TreeMap(rows);
resultsList.add(Collections.unmodifiableMap(sortedMap));
Any help would be appreciated.
[2593 byte] By [
pjamWeb76a] at [2007-11-27 2:24:09]

I've tried different ways within JSTL to get it to work.
I thought maybe i stored my bean wrong or something.
The only thing that seems to work is storing each result in a HashMap and then stroring the Map in a ArrayList. Then I use JSTL. to display the data.
But ${cell} is the only thing that works. It displays all the rows and columns, but sometimes I need to change the <td> color according to what data goes in there. and ${cell[1]} or cell.value[1] and so on, none of that works. It never comes up with an error, just a blank html page.
Here is what my jstl looks like : It works when i store my results in a Map and then put that Map into an ArrayList.
<c:forEach items="${listResults}" var="row" varStatus="loop">
<c:forEach items="${row}" var="cell">
<tr>
<td>${cell.value}</td>
</tr>
</c:forEach>
</c:forEach>
What I need is to do something like
<td bgcolor="red">${cell.value[1]}</td>
<td bgcolor="blue"></td>and so on.
But i only get a blank html page when I do it that way.
{listResults} is my ArrayList sent from the servlet with the stored javaBean results.
I tried the JSTL code below but it came back with a blank html page.
<c:forEach items="${listResults}" var="row" varStatus="loop">
<tr>
<td>${row.bms}</td>
<td>${row.mcc}</td>
</tr>
</c:forEach>
The only thing that seems to work is if I store the results in a HashMap, then add those to the ArrayList and use JSTL to display the data
<c:forEach items="${listResults}" var="row" varStatus="loop">
<c:forEach items="${row} var="cell">
<tr>
<td>${cell.value}</td>
</tr>
</c:forEach>
</c:forEach>
Not sure what I'm doing wrong at this point.
Message was edited by:
pjamWeb76
Message was edited by:
pjamWeb76