Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / June 2005

Tip: Looking for answers? Try searching our database.

Question about Struts <logic:iterate> tag

Thread view: 
javadude - 30 Jun 2005 16:06 GMT
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.
Scott Phelps - 30 Jun 2005 17:43 GMT
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"/>

>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
[quoted text clipped - 24 lines]
> What am I doing wrong?
> Thanks in advance.
Wendy Smoak - 30 Jun 2005 19:55 GMT
> request.setAttribute("foos", fooList);
> // forward to JSP for display
[quoted text clipped - 9 lines]
> 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.)

Signature

Wendy Smoak



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.