Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Question about Struts <logic:iterate> tag

Reply
Thread Tools

Question about Struts <logic:iterate> tag

 
 
javadude
Guest
Posts: n/a
 
      06-30-2005
I have an action class that creates an ArrayList of Foo objects and
then sets them in the request. Note I am putting the list itself
directly into the request:

FooAction.java:
List fooList = new ArrayList();
for (int i = 0; i < 3; i++)
{
String id = "ID" + i;
Foo f = new Foo(id);
fooList.add(f);
}
request.setAttribute("foos", fooList);
// forward to JSP for display


In my JSP, I want to iterate over and display the Foo objects and
display their IDs.

I have:
<logic:iterate id="nextElement" name="foos">
<br>NextFoo<bean:write name="nextElement" property="id" /></b>
</logic:iterate>

However, I get the error:
Cannot find bean nextElement in any scope'

What am I doing wrong?
Thanks in advance.

 
Reply With Quote
 
 
 
 
Scott Phelps
Guest
Posts: n/a
 
      06-30-2005

The jsp has to know where to access the bean. If it is just in the page put
this at the top,
<jsp:useBean id="foos" scope="session" class="java.util.ArrayList"/>


"javadude" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
>I have an action class that creates an ArrayList of Foo objects and
> then sets them in the request. Note I am putting the list itself
> directly into the request:
>
> FooAction.java:
> List fooList = new ArrayList();
> for (int i = 0; i < 3; i++)
> {
> String id = "ID" + i;
> Foo f = new Foo(id);
> fooList.add(f);
> }
> request.setAttribute("foos", fooList);
> // forward to JSP for display
>
>
> In my JSP, I want to iterate over and display the Foo objects and
> display their IDs.
>
> I have:
> <logic:iterate id="nextElement" name="foos">
> <br>NextFoo<bean:write name="nextElement" property="id" /></b>
> </logic:iterate>
>
> However, I get the error:
> Cannot find bean nextElement in any scope'
>
> What am I doing wrong?
> Thanks in advance.
>



 
Reply With Quote
 
 
 
 
Wendy Smoak
Guest
Posts: n/a
 
      06-30-2005
"javadude" <(E-Mail Removed)> wrote:

> request.setAttribute("foos", fooList);
> // forward to JSP for display
>
> In my JSP, I want to iterate over and display the Foo objects and
> display their IDs.
>
> I have:
> <logic:iterate id="nextElement" name="foos">
> <br>NextFoo<bean:write name="nextElement" property="id" /></b>
> </logic:iterate>
>
> However, I get the error:
> Cannot find bean nextElement in any scope'


You code (slightly modified) worked fine for me, so my guess is that
something's NQR with how you're filling the List or placing it in the
request. That or the code you posted isn't actually the code that's
producing the error.

Here's some code you can include at the bottom of your JSP...
http://wiki.wendysmoak.com/cgi-bin/wiki.pl?DebugJSP
It just prints out everything in the request/session/context... make sure
everything is where you think it is.

For starters, try just <bean:write name="foos" /> and make sure it can find
the list, and that the list has what you think it has in it. Hopefully your
'Foo' class has a good 'toString' method.

(You don't have to <jsp:usebean> with the Struts tags, it knows how to look
in the various scopes to find objects. Anyway, it's not complaining about
'foos', it's complaining about 'nextElement' inside the iteration.)

--
Wendy Smoak


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how do u invoke Tag b's Tag Handler from within Tag a's tag Handler? shruds Java 1 01-27-2006 03:00 AM
Simple Struts question: how can I add the value of a bean variable to arg0 of the bean:message tag? Thomas P. Fuller Java 1 08-17-2004 01:42 AM
Struts and the html:base tag question, can't see images Mehmet Gunacti Java 1 02-05-2004 02:00 PM
Struts - logic tag question Igor Java 2 07-14-2003 11:07 PM
struts tag inside a tag kishan bisht Java 1 07-08-2003 11:04 PM



Advertisments