You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Basu, Abhijit (Abhi)" <ab...@paetec.com> on 2004/04/29 16:38:30 UTC
Problem with logic:iterate tag
I am trying something very simple. Assume all imports have been done
correctly, I will post chunks of the code here.
Summary:
I do not have a form bean in this example. Basically have a link that calls
an action findContact action class that makes a connection to an Oracle db
using another connection class and executes a stored proc that returns a
resultset. I also have a class called ContactObject that holds the props
like contact name, address, country and I stuff values from the recordset
in this object and in turn stuff them inside a vector and put it in the
session so my jsp page can use the vector. (See code excerpts below).
1. I have a jsp file called index.jsp that has a link which does the
following:
<p><html:link page="/findContact.do">Find Contacts List</html:link>
--------------------------------------------------------------------------
2. Struts.config file has the following entry:
<action-mappings>
<action path="/findContact"
type="com.paetec.pinnacle.al.GetContactAction"
input="/index.jsp"
scope="request">
<forward name="success" path="/contact_details_struts.jsp" />
<forward name="failure" path="/contact_details_struts.jsp" />
</action>
</action-mappings>
--------------------------------------------------------------------------
3. ContactObject is a simple class with getters and setters for the
contact elements.
--------------------------------------------------------------------------
4. GetContactAction class excerpt:
//CBean makes the db connection and performs the query
cBean.makeConnection();
rs = (ResultSet)cBean.getContacts();
//Convert resultset into vector of contact objects to be passed to the jsp
thru request
Vector v = new Vector();
while (rs.next())
{
ContactObject cObj = new ContactObject();
cObj.setFirstName(rs.getString("fname"));
cObj.setLastName(rs.getString("lname"));
cObj.setAddress(rs.getString("email"));
cObj.setCountry(rs.getString("country"));
v.add(cObj);
}
System.out.println("Vector Size = " + v.size());
//Pass recordset to JSP
//request.setAttribute("lsContacts", v);
request.getSession(true).setAttribute("lstContacts", v);
--------------------------------------------------------------------------
5. jsp code excerpt:
<logic:iterate id="c" name="lstContacts" scope="session"
type="com.paetec.pinnacle.al.ContactObject"/>
<tr>
<td width="184" bgcolor="white">
<bean:write name="c" property="lastName"/>, <bean:write name="c"
property="firstName"/>
</td>
<td width="184" bgcolor="white">
<bean:write name="c" property="country"/>
</td>
<td width="184" bgcolor="white">
<bean:write name="c" property="address"/>
</td>
</tr>
</logic:iterate>
--------------------------------------------------------------------------
I put a debug statement and found out that my vector is being loaded
with 417 elements (each ContactObject). However, the jsp page only
displays the last element from the vector, not all 417 rows!! Any
ideas? Any help is greatly appreciated. I am new to Struts, as you
can say.
Thanks.
Abhi Basu.
Software Systems Engineer
PaeTec Communications Inc.
Phone: 585-340-8278
Email: abhi.basu@paetec.com
Re: Problem with logic:iterate tag
Posted by Niall Pemberton <ni...@blueyonder.co.uk>.
Your openning logic:iterate ends with "/>" - instead of
<logic:iterate id="c" name="lstContacts" scope="session"
type="com.paetec.pinnacle.al.ContactObject"/>
try
<logic:iterate id="c" name="lstContacts" scope="session"
type="com.paetec.pinnacle.al.ContactObject">
----- Original Message -----
From: "Basu, Abhijit (Abhi)" <ab...@paetec.com>
To: <us...@struts.apache.org>
Sent: Thursday, April 29, 2004 3:38 PM
Subject: Problem with logic:iterate tag
> I am trying something very simple. Assume all imports have been done
> correctly, I will post chunks of the code here.
> Summary:
> I do not have a form bean in this example. Basically have a link that
calls
> an action findContact action class that makes a connection to an Oracle db
> using another connection class and executes a stored proc that returns a
> resultset. I also have a class called ContactObject that holds the props
> like contact name, address, country and I stuff values from the recordset
> in this object and in turn stuff them inside a vector and put it in the
> session so my jsp page can use the vector. (See code excerpts below).
>
> 1. I have a jsp file called index.jsp that has a link which does the
> following:
> <p><html:link page="/findContact.do">Find Contacts List</html:link>
> --------------------------------------------------------------------------
> 2. Struts.config file has the following entry:
> <action-mappings>
> <action path="/findContact"
> type="com.paetec.pinnacle.al.GetContactAction"
> input="/index.jsp"
> scope="request">
> <forward name="success" path="/contact_details_struts.jsp" />
> <forward name="failure" path="/contact_details_struts.jsp" />
> </action>
> </action-mappings>
> --------------------------------------------------------------------------
> 3. ContactObject is a simple class with getters and setters for the
> contact elements.
> --------------------------------------------------------------------------
> 4. GetContactAction class excerpt:
> //CBean makes the db connection and performs the query
> cBean.makeConnection();
> rs = (ResultSet)cBean.getContacts();
>
> //Convert resultset into vector of contact objects to be passed to the jsp
> thru request
> Vector v = new Vector();
>
> while (rs.next())
> {
> ContactObject cObj = new ContactObject();
> cObj.setFirstName(rs.getString("fname"));
> cObj.setLastName(rs.getString("lname"));
> cObj.setAddress(rs.getString("email"));
> cObj.setCountry(rs.getString("country"));
> v.add(cObj);
> }
>
> System.out.println("Vector Size = " + v.size());
>
> //Pass recordset to JSP
> //request.setAttribute("lsContacts", v);
> request.getSession(true).setAttribute("lstContacts", v);
> --------------------------------------------------------------------------
> 5. jsp code excerpt:
> <logic:iterate id="c" name="lstContacts" scope="session"
> type="com.paetec.pinnacle.al.ContactObject"/>
> <tr>
> <td width="184" bgcolor="white">
> <bean:write name="c" property="lastName"/>, <bean:write name="c"
> property="firstName"/>
> </td>
> <td width="184" bgcolor="white">
> <bean:write name="c" property="country"/>
> </td>
> <td width="184" bgcolor="white">
> <bean:write name="c" property="address"/>
> </td>
> </tr>
> </logic:iterate>
> --------------------------------------------------------------------------
> I put a debug statement and found out that my vector is being loaded
> with 417 elements (each ContactObject). However, the jsp page only
> displays the last element from the vector, not all 417 rows!! Any
> ideas? Any help is greatly appreciated. I am new to Struts, as you
> can say.
> Thanks.
>
>
> Abhi Basu.
> Software Systems Engineer
> PaeTec Communications Inc.
> Phone: 585-340-8278
> Email: abhi.basu@paetec.com
>
>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org