You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by e-denton Java Programmer <ja...@e-denton.com> on 2003/12/24 19:23:58 UTC
Easy question: iterate
Sorry to bother you with an easy question, but I can't find the answer.
I want to iterate over Category_VO[] which is stored in a session attribute.
I read that it can be done, but I can't find an example for raw arrays.
Here's what I have (which probably doesn't even make sense):
<logic:iterate
id="category"
collection="com.cnw.portal.database.Category_VO"
type="com.cnw.portal.database.Category_VO"
scope="session">
<p> <bean:write name="category" property="shortTitle"/>
</logic:iterate>
Thanks!
will
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: Easy question: iterate
Posted by Mark Lowe <ma...@talk21.com>.
Looks like you should copy what your view needs from your model rather
than shoe-horning in your data objects into your jsps.
Have a simple bean called Category in this example with a title
property.
Category_VO[] pcatResults = dao.selectTopLevel();
ArrayList categoryList = new ArrayList();
while(pcatResults.next()) {
Category category = new Category();
String title = pcatResults.getShortTitle();
category.setTitle(title);
categoryList.add(category);
}
request.setAttribute("categories", categoryList.toArray());
Any good?
Wont need the useBean stuff, i just didn't know what you were trying.
Cheers Mark
On 24 Dec 2003, at 19:20, e-denton Java Programmer wrote:
> Hi Mark,
>
> I tried this:
>
> Category_VO[] pcatResults = null;
> Category_DAO dao= new Category_DAO();
> pcatResults = dao.selectTopLevel();
> request.getSession (true).setAttribute ("PCAT", pcatResults);
> ---
> <jsp:useBean id="PCAT" class="com.cnw.portal.database.Category_VO"
> scope="session" />
>
> <logic:iterate id="category" name="PCAT">
> <p><bean:write name="category" property="shortTitle"/>
> </logic:iterate>
>
> and, I get this:
>
> javax.servlet.jsp.JspException: Cannot create iterator for this
> collection
>
>
> Will
>
> ----- Original Message -----
> From: "Mark Lowe" <ma...@talk21.com>
> To: "Struts Users Mailing List" <st...@jakarta.apache.org>
> Sent: Wednesday, December 24, 2003 12:31 PM
> Subject: Re: Easy question: iterate
>
>
>>
>> //psuedo code.
>> List categoryList = Category.getList();
>>
>> request.setAttribute("categories", categoryList.toArray());
>>
>> <logic:iterate id="category" name="categories">
>>
>> </logic:iterate>
>>
>> I made the first bit up. But should give you the idea.
>>
>> <jsp:useBean id="categories"
>> class="com.cnw.portal.database.Category_VO" scope="request" />
>>
>> may do what you want.. Depends on what methods you've got in there..
>>
>> Cheers Mark
>>
>>
>> On 24 Dec 2003, at 18:23, e-denton Java Programmer wrote:
>>
>>> Sorry to bother you with an easy question, but I can't find the
>>> answer.
>>>
>>> I want to iterate over Category_VO[] which is stored in a session
>>> attribute.
>>> I read that it can be done, but I can't find an example for raw
>>> arrays.
>>>
>>> Here's what I have (which probably doesn't even make sense):
>>>
>>> <logic:iterate
>>> id="category"
>>> collection="com.cnw.portal.database.Category_VO"
>>> type="com.cnw.portal.database.Category_VO"
>>> scope="session">
>>> <p> <bean:write name="category" property="shortTitle"/>
>>> </logic:iterate>
>>>
>>>
>>> Thanks!
>>>
>>> will
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>>> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: Easy question: iterate
Posted by e-denton Java Programmer <ja...@e-denton.com>.
Hi Mark,
I tried this:
Category_VO[] pcatResults = null;
Category_DAO dao= new Category_DAO();
pcatResults = dao.selectTopLevel();
request.getSession (true).setAttribute ("PCAT", pcatResults);
---
<jsp:useBean id="PCAT" class="com.cnw.portal.database.Category_VO"
scope="session" />
<logic:iterate id="category" name="PCAT">
<p><bean:write name="category" property="shortTitle"/>
</logic:iterate>
and, I get this:
javax.servlet.jsp.JspException: Cannot create iterator for this
collection
Will
----- Original Message -----
From: "Mark Lowe" <ma...@talk21.com>
To: "Struts Users Mailing List" <st...@jakarta.apache.org>
Sent: Wednesday, December 24, 2003 12:31 PM
Subject: Re: Easy question: iterate
>
> //psuedo code.
> List categoryList = Category.getList();
>
> request.setAttribute("categories", categoryList.toArray());
>
> <logic:iterate id="category" name="categories">
>
> </logic:iterate>
>
> I made the first bit up. But should give you the idea.
>
> <jsp:useBean id="categories"
> class="com.cnw.portal.database.Category_VO" scope="request" />
>
> may do what you want.. Depends on what methods you've got in there..
>
> Cheers Mark
>
>
> On 24 Dec 2003, at 18:23, e-denton Java Programmer wrote:
>
> > Sorry to bother you with an easy question, but I can't find the answer.
> >
> > I want to iterate over Category_VO[] which is stored in a session
> > attribute.
> > I read that it can be done, but I can't find an example for raw arrays.
> >
> > Here's what I have (which probably doesn't even make sense):
> >
> > <logic:iterate
> > id="category"
> > collection="com.cnw.portal.database.Category_VO"
> > type="com.cnw.portal.database.Category_VO"
> > scope="session">
> > <p> <bean:write name="category" property="shortTitle"/>
> > </logic:iterate>
> >
> >
> > Thanks!
> >
> > will
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: struts-user-help@jakarta.apache.org
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: Easy question: iterate
Posted by Mark Lowe <ma...@talk21.com>.
//psuedo code.
List categoryList = Category.getList();
request.setAttribute("categories", categoryList.toArray());
<logic:iterate id="category" name="categories">
</logic:iterate>
I made the first bit up. But should give you the idea.
<jsp:useBean id="categories"
class="com.cnw.portal.database.Category_VO" scope="request" />
may do what you want.. Depends on what methods you've got in there..
Cheers Mark
On 24 Dec 2003, at 18:23, e-denton Java Programmer wrote:
> Sorry to bother you with an easy question, but I can't find the answer.
>
> I want to iterate over Category_VO[] which is stored in a session
> attribute.
> I read that it can be done, but I can't find an example for raw arrays.
>
> Here's what I have (which probably doesn't even make sense):
>
> <logic:iterate
> id="category"
> collection="com.cnw.portal.database.Category_VO"
> type="com.cnw.portal.database.Category_VO"
> scope="session">
> <p> <bean:write name="category" property="shortTitle"/>
> </logic:iterate>
>
>
> Thanks!
>
> will
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org