You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Team Gasoline <te...@earthlink.net> on 2002/01/13 01:06:10 UTC
iterate only showing one row -- newbie question
Hi All --
The following iterate code only shows up as one row in my jsp. With the
debug code I know that the arrayList is being populated with all the
beans representing my resultSet. The row that appears seems to be the
last row to be obtained. What is happening with the rest??? Thanks for
your help!
--------------------------------------------------------------------------------------------------jsp
Here is the 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/struts-template.tld' prefix='template' %>
<%@ page import="java.util.*" %>
<app:checkLogon/>
<head>
<!--<title><bean:message key="logon.title"/></title> -->
</head>
<body bgcolor="#666666">
<% Object obj = getServletContext().getAttribute("appInfoPick");
if (obj == null) {
System.out.println("The action wasn't called before this
jsp...no session");
} else {
System.out.println("appInfoPick is a " + obj.getClass().getName());
}
%>
<TABLE BORDER="1" ALIGN="center" BGCOLOR="#666699" CELLSPACING="1"
CELLPADDING="10">
<tr>
<th align="center">
<bean:message key="heading.playerTeamPick.number"/>
</th>
<th align="center">
<bean:message key="heading.playerTeamPick.driver"/>
</th>
<th align="center">
<bean:message key="heading.playerTeamPick.qualification"/>
s</th>
<th align="center">
<bean:message key="heading.playerTeamPick.cost"/>
</th>
<th align="center">
<bean:message key="heading.playerTeamPick.pick"/>
</th>
</tr>
<logic:iterate id="appInfoPick" name="appInfo" property="appInfoPicks" />
<tr>
<% Object obj1 = getServletContext().getAttribute("appInfo");
System.out.println("IN iterate ------------1" + obj1.toString());%>
<td align="left">
<bean:write name="appInfoPick" property="driverNumber" />
</td>
<td align="left">
<bean:write name="appInfoPick" property="driver" />
</td>
<td align="left">
<bean:write name="appInfoPick" property="startingPosition" />
</td>
<td align="left">
<bean:write name="appInfoPick" property="driverPrice" />
</td>
<% System.out.println("IN iterate ------------2");%>
</tr>
</logic:iterate>
</table>
</body>
</html:html>
--------------------------------------------------------------------------------------------------bean
AppInfo.java wraps the arrayList of AppInfoPick beans.
package com.teamgasoline.webapp;
import java.io.Serializable;
import java.util.*;
public final class AppInfo {
private ArrayList list = null;
private int size = 0;
public int getSize() {
return list.size();
}
public AppInfo() {
list = new ArrayList();
System.out.println("new list created AppInfo
Constructor------------> : " + list.size());
}
public AppInfo(ArrayList newList) {
list = newList;
}
public void addAppInfoPick(AppInfoPick appInfoPick) {
list.add(appInfoPick);
System.out.println("AppInfoPick added to
list------------> : " + list.size());
}
public void removeAppInfoPick(int appInfoPickID) {
list.remove(appInfoPickID);
list.trimToSize();
}
public ArrayList getAppInfoPicks() {
ArrayList appInfoPicks = list;
System.out.println("IN getAppInfoPicks() --- index 1 : " +
((AppInfoPick)list.get(0)).getDriver());
System.out.println("IN getAppInfoPicks() --- index 2 : " +
((AppInfoPick)list.get(1)).getDriver());
System.out.println("IN getAppInfoPicks() --- index 3 : " +
((AppInfoPick)list.get(2)).getDriver());
System.out.println("IN getAppInfoPicks() --- index 4 : " +
((AppInfoPick)list.get(3)).getDriver());
System.out.println("IN getAppInfoPicks() --- index 5 : " +
((AppInfoPick)list.get(4)).getDriver());
System.out.println("IN getAppInfoPicks() --- index 6 : " +
((AppInfoPick)list.get(5)).getDriver());
System.out.println("IN getAppInfoPicks() --- index 7 : " +
((AppInfoPick)list.get(6)).getDriver());
System.out.println("IN getAppInfoPicks() --- index 8 : " +
((AppInfoPick)list.get(7)).getDriver());
System.out.println("IN getAppInfoPicks() --- index 9 : " +
((AppInfoPick)list.get(8)).getDriver());
return appInfoPicks;
}
public AppInfoPick getAppInfoPick(int appInfoPickID) {
AppInfoPick appInfoPick = new AppInfoPick();
appInfoPick = (AppInfoPick)list.get(appInfoPickID);
return appInfoPick;
}
-----------------------------------------------------------------------------------------------------------------------------bean
AppInfoPick is where I'm storing the data
package com.teamgasoline.webapp;
import java.io.Serializable;
import java.util.*;
public final class AppInfoPick implements Serializable {
private String driverNumber;
private String driver;
private String startingPosition;
private String driverPrice;
public AppInfoPick() {
}
public String getDriverNumber() {
System.out.println("driverNumber has been obtained : " + driverNumber);
return (this.driverNumber);
}
public void setDriverNumber(String driverNumber) {
this.driverNumber = driverNumber;
System.out.println("driverNumber has been set to : " + driverNumber);
}
public String getDriver() {
System.out.println("driver has been obtained : " + driver);
return (this.driver);
}
public void setDriver(String driver) {
this.driver = driver;
System.out.println("driver has been set to : " + driver);
}
public String getStartingPosition() {
System.out.println("startingPosition has been obtained : " +
startingPosition);
return (this.startingPosition);
}
public void setStartingPosition(String startingPosition) {
this.startingPosition = startingPosition;
System.out.println("startingPosition has been set to : " +
startingPosition);
}
public String getDriverPrice() {
System.out.println("driverPrice has been obtained : " + driverPrice);
return (this.driverPrice);
}
public void setDriverPrice(String driverPrice) {
this.driverPrice = driverPrice;
System.out.println("driverPrice has been set to : " + driverPrice);
}
}
-----------------------------------------------------------------------------------------------------------------------Action
and here is my Action.
package com.teamgasoline.webapp;
import java.io.IOException;
import java.util.Hashtable;
import java.util.ArrayList;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.*;
import org.apache.struts.util.MessageResources;
import javax.sql.*;
import java.sql.*;
public final class PlayerPickAction extends Action {
public ActionForward perform(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
System.out.println("TOP of
PlayerPickAction------------------------------->");
AppInfo appInfo = new AppInfo(); //--------------
servlet.getServletContext().setAttribute("appInfo", appInfo);
//request.setAttribute("appInfo", appInfo);
AppInfoPick appInfoPick = new AppInfoPick();
servlet.getServletContext().setAttribute("appInfoPick", appInfoPick);
//request.setAttribute("appInfoPick", appInfoPick);
AppInfoPick appInfoPicks[] = new AppInfoPick[9];
int n = 0;
Statement statement = null;
ResultSet resultSet = null;
Connection conn = null;
try {
DataSource dataSource =
(DataSource)servlet.getServletContext().getAttribute(Action.DATA_SOURCE_KEY)
;
conn = dataSource.getConnection();
statement = conn.createStatement();
resultSet = statement.executeQuery( "SELECT a.driverNumber, " +
"a.driverName, " +
"b.startingPosition, " +
"a.driverPrice " +
"FROM drivers a, race_qual b " +
"WHERE a.driverID = b.driverID and " +
"raceID = 1 " +
"ORDER BY a.driverPrice");
if (resultSet != null) {
while (resultSet.next()) {
appInfoPicks[n] = new AppInfoPick();
appInfoPicks[n].setDriverNumber(resultSet.getString("driverNumber"));
appInfoPicks[n].setDriver(resultSet.getString("driverName"));
appInfoPicks[n].setStartingPosition(resultSet.getString("startingPosition"
));
appInfoPicks[n].setDriverPrice(resultSet.getString("driverPrice"));
appInfo.addAppInfoPick(appInfoPicks[n]);
System.out.println("Just loaded starting position ---> " +
resultSet.getString("startingPosition"));
System.out.println("Just loaded appInfoPicks[" +
n + "] ---> " + appInfoPicks[n]);
n++;
}
} else {
System.out.println("Error: resultSet is NULL");
}
} catch (Exception e) {
System.out.println("Error in PlayerPickAction :" + e.getMessage());
} finally {
try {
if (conn != null) {
conn.close();
}
} catch (SQLException e) {
System.out.println("SQL problem : " + e.getMessage());
}
}
System.out.println("PlayerPickAction-------------------------------------
BOTTOM");
if (true) {
return mapping.findForward("PlayerPickSuccess");
} else {
return mapping.findForward("failure");
}
}
}
---------------------------------------------------------------------------------------------------------
With System.out.println I have verified that the list in AppInfo
contains the 9 different AppInfoPick beans. If I replace the bean:write
tags in the iterate with just text or just the name of the bean without
the property attribute, I expect that iterate should iterate through all
objects in the list or print the text in rows equal to the
ArrayList.size(), which does not happen, but I do get that one row. Also
if I add a scope attribute to the bean:write tags I receive one row of
null that's all.
Thanks again!
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: iterate only showing one row -- newbie question
Posted by Team Gasoline <te...@earthlink.net>.
Thanks for your reply, I have checked out your nested:iterate and it
looks very interesting. And for my problem, if you look in my jsp I have
closed the iterate tag twice, this was why I was only printing out the
last row of the resultSet and not all of them. Cheers!
<logic:iterate id="appInfoPick" name="appInfo"
property="appInfoPicks"/> <--------this "/" shouldn't have been
there.
<tr>
<% Object obj1 = getServletContext().getAttribute("appInfo");
System.out.println("IN iterate ------------1" + obj1.toString());%>
<td align="left">
<bean:write name="appInfoPick" property="driverNumber" />
</td>
</tr>
</logic:iterate>
On Saturday, January 12, 2002, at 11:15 PM, Arron wrote:
> Wow, that's a lot of code there mate. :)
>
> I really do recommend using the nested extension for this. It's an
> exact fit for what you're trying to do.
> http://www.keyboardmonkey.com/strtus
>
> There's all the information you need to get running. Primer, tutorial
> if you need it, and stuff for the future.
>
> To put it bluntly... original struts iterate tags using nested objects
> is simply s--t. And to not use a nested bean creates s--t bean code.
> The nested extension will fix all that for you, and you'll end up with
> your JSP looking like this...
>
> Start JSP --==>>
> <div align="center">
> <table cellspacing="1" cellpadding="10" border="1" bgcolor="#666699">
> <tr>
> <th align="center"> <bean:message
> key="heading.playerTeamPick.number"/> </th>
> <th align="center"> <bean:message
> key="heading.playerTeamPick.driver"/> </th>
> <th align="center"> <bean:message
> key="heading.playerTeamPick.qualification"/> </th>
> <th align="center"> <bean:message
> key="heading.playerTeamPick.cost"/> </th>
> <th align="center"> <bean:message
> key="heading.playerTeamPick.pick"/> </th>
> </tr>
> <nested:iterate property="appInfoPicks" />
> <tr>
> <td align="left"> <bean:write property="driverNumber" /> </td>
> <td align="left"> <bean:write property="driver" /> </td>
> <td align="left"> <bean:write property="startingPosition" />
> </td>
> <td align="left"> <bean:write property="driverPrice" /> </td>
> </tr>
> </nested:iterate>
> </table>
> </div>
> <<==-- End JSP
>
> ...it could be just me, but I think that the short-and-sweet aspect of
> such markup is truly compelling. And there's other things possible with
> it beside this application alone.
>
> And don't worry, the Nested Extension's destiny is to be in Struts
> itself, I'm just building up it's user base to get feedback and make it
> stronger before the developers commit it to Struts itself.
>
> You have a good nesting model happening. You understand that part, and
> that's the most important.
> Give it a try and get back to the group with how it goes.
>
>
> Arron.
>
>
>
>
> Team Gasoline wrote:
>
>> Hi All --
>>
>>
>> The following iterate code only shows up as one row in my jsp. With
>> the debug code I know that the arrayList is being populated with all
>> the beans representing my resultSet. The row that appears seems to be
>> the last row to be obtained. What is happening with the rest??? Thanks
>> for your help! ....
>
> ...
>
>> With System.out.println I have verified that the list in AppInfo
>> contains the 9 different AppInfoPick beans. If I replace the
>> bean:write tags in the iterate with just text or just the name of the
>> bean without the property attribute, I expect that iterate should
>> iterate through all objects in the list or print the text in rows
>> equal to the ArrayList.size(), which does not happen, but I do get
>> that one row. Also if I add a scope attribute to the bean:write tags I
>> receive one row of null that's all.
>>
>>
>> Thanks again!
>
>
>
> --
> To unsubscribe, e-mail: <mailto:struts-user-
> unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: <mailto:struts-user-
> help@jakarta.apache.org>
>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: Digester Examples
Posted by Ted Husted <hu...@apache.org>.
The Digester is now a Commons component.
http://jakarta.apache.org/commons/digester.html
Phase Communcations wrote:
>
> Does anyone know of some good concise digester examples and tutorials. I
> have been reading the docs but am unsure of several aspects of it.
>
> Brandon Goodin
> Phase Web and Multimedia
> P (406) 862-2245
> F (406) 862-0354
> mail@phase.ws
> http://www.phase.ws
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
[I FIGURED IT OUT :-)] Digester Examples
Posted by Phase Communcations <ma...@phase.ws>.
Thanks for the info. I figured it out. I see the digester playing an
incredible role in what I am doing. What an incredible tool!
-----Original Message-----
From: Phase Communcations [mailto:mail@phase.ws]
Sent: Saturday, January 12, 2002 10:25 PM
To: Struts Users Mailing List
Subject: Digester Examples
Does anyone know of some good concise digester examples and tutorials. I
have been reading the docs but am unsure of several aspects of it.
Brandon Goodin
Phase Web and Multimedia
P (406) 862-2245
F (406) 862-0354
mail@phase.ws
http://www.phase.ws
--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: Digester Examples
Posted by Sandeep Takhar <sa...@yahoo.com>.
the sample application has most of what is necessary.
I do remember having problems with the digester when I
was doing my own poc however and that was after
understanding the example app and reading the docs.
I think the example app is part of the source download
for struts 1.0
Sandeep
--- Phase Communcations <ma...@phase.ws> wrote:
> Does anyone know of some good concise digester
> examples and tutorials. I
> have been reading the docs but am unsure of several
> aspects of it.
>
> Brandon Goodin
> Phase Web and Multimedia
> P (406) 862-2245
> F (406) 862-0354
> mail@phase.ws
> http://www.phase.ws
>
>
>
> --
> To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
>
__________________________________________________
Do You Yahoo!?
Send FREE video emails in Yahoo! Mail!
http://promo.yahoo.com/videomail/
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Digester Examples
Posted by Phase Communcations <ma...@phase.ws>.
Does anyone know of some good concise digester examples and tutorials. I
have been reading the docs but am unsure of several aspects of it.
Brandon Goodin
Phase Web and Multimedia
P (406) 862-2245
F (406) 862-0354
mail@phase.ws
http://www.phase.ws
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: iterate only showing one row -- newbie question
Posted by Arron <ar...@pacific.net.au>.
Wow, that's a lot of code there mate. :)
I really do recommend using the nested extension for this. It's an exact
fit for what you're trying to do.
http://www.keyboardmonkey.com/strtus
There's all the information you need to get running. Primer, tutorial if
you need it, and stuff for the future.
To put it bluntly... original struts iterate tags using nested objects
is simply s--t. And to not use a nested bean creates s--t bean code. The
nested extension will fix all that for you, and you'll end up with your
JSP looking like this...
Start JSP --==>>
<div align="center">
<table cellspacing="1" cellpadding="10" border="1" bgcolor="#666699">
<tr>
<th align="center"> <bean:message
key="heading.playerTeamPick.number"/> </th>
<th align="center"> <bean:message
key="heading.playerTeamPick.driver"/> </th>
<th align="center"> <bean:message
key="heading.playerTeamPick.qualification"/> </th>
<th align="center"> <bean:message
key="heading.playerTeamPick.cost"/> </th>
<th align="center"> <bean:message
key="heading.playerTeamPick.pick"/> </th>
</tr>
<nested:iterate property="appInfoPicks" />
<tr>
<td align="left"> <bean:write property="driverNumber" /> </td>
<td align="left"> <bean:write property="driver" /> </td>
<td align="left"> <bean:write property="startingPosition" /> </td>
<td align="left"> <bean:write property="driverPrice" /> </td>
</tr>
</nested:iterate>
</table>
</div>
<<==-- End JSP
...it could be just me, but I think that the short-and-sweet aspect of
such markup is truly compelling. And there's other things possible with
it beside this application alone.
And don't worry, the Nested Extension's destiny is to be in Struts
itself, I'm just building up it's user base to get feedback and make it
stronger before the developers commit it to Struts itself.
You have a good nesting model happening. You understand that part, and
that's the most important.
Give it a try and get back to the group with how it goes.
Arron.
Team Gasoline wrote:
> Hi All --
>
>
> The following iterate code only shows up as one row in my jsp. With
> the debug code I know that the arrayList is being populated with all
> the beans representing my resultSet. The row that appears seems to be
> the last row to be obtained. What is happening with the rest??? Thanks
> for your help! ....
...
> With System.out.println I have verified that the list in AppInfo
> contains the 9 different AppInfoPick beans. If I replace the
> bean:write tags in the iterate with just text or just the name of the
> bean without the property attribute, I expect that iterate should
> iterate through all objects in the list or print the text in rows
> equal to the ArrayList.size(), which does not happen, but I do get
> that one row. Also if I add a scope attribute to the bean:write tags I
> receive one row of null that's all.
>
>
> Thanks again!
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>