*
The moose likes Struts and the fly likes howto use JSTL foreach to display list ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "howto use JSTL foreach to display list ?" Watch "howto use JSTL foreach to display list ?" New topic
Author

howto use JSTL foreach to display list ?

Nakata kokuyo
Ranch Hand

Joined: Apr 13, 2005
Posts: 438
good day to all ,

if i have a list named "retMenuList" , which is collection of "User" Object , in order to list out all User object properties named "username"?

how to i use c:foreach to display out the username for each user?

i have try this


but it seem not working ? anyone know how to resolve this problem, many thanks in advance
[ September 05, 2006: Message edited by: Nakata kokuyo ]
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6



You were close. forEach does the magic for you of yanking out the object from the list. You don't have to explicitly tell forEach what object to pull out, since the List would contains only a list of 1 type of object, User.
[ September 05, 2006: Message edited by: Gregg Bolinger ]

GenRocket - Experts at Building Test Data
Nakata kokuyo
Ranch Hand

Joined: Apr 13, 2005
Posts: 438
hi, Gregg , thanks for reply, this is my real code for testing
when i use the following test code in jsp


it able to show the result out

however, it give me error while happen in foreach


the error is "SEVERE: ServletException in '/pages/topheader.jsp': Unable to find a value for "
top_menu_name" in object of class "java.lang.String" using operator "."
javax.servlet.ServletException: Unable to find a value for "top_menu_name" in object of class "java.lang.String" using operator ".""

do you have any idea why is it happen ?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60785
    
  65

Since the <html:link> action is a Struts action, I'm moving this to the Struts forum. Please be sure to post questions on Struts and Struts tags there.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Nakata kokuyo
Ranch Hand

Joined: Apr 13, 2005
Posts: 438
Bear, the doubt is on foreach tag, so i put it in jstl forum ,

anyway, when i try on this


the following is not show result, but it give no error


but following statement give me result=1


anyone have idea on this ? many thanks
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1016
You are missing the ${ } around the retMenuLists attribute, so it interprets it as a String rather than an expression.

Nakata kokuyo
Ranch Hand

Joined: Apr 13, 2005
Posts: 438
oh, my god !!
Stefan Evans ,thanks for pointing out the mistake , it have been solved by your suggestion,

thank you very much to stefan and Gregg for helping
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: howto use JSTL foreach to display list ?
 
Similar Threads
Ant javac task and subdirectories
Iframe to automatic update in jsp according to the database
question regarding el
How do I execute correct substring on bean:message?
Select & Convert Memory Stream Image to PDF File Using Aspose.Pdf