This week's book giveaway is in the Artificial Intelligence forum.
We're giving away four copies of Pragmatic AI and have Noah Gift on-line!
See this thread for details.
Win a copy of Pragmatic AI this week in the Artificial Intelligence forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

howto use JSTL foreach to display list ?  RSS feed

 
Ranch Hand
Posts: 472
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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 ]
 
Nakata kokuyo
Ranch Hand
Posts: 472
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?
 
Author and ninkuma
Marshal
Posts: 66789
168
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Nakata kokuyo
Ranch Hand
Posts: 472
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 1844
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are missing the ${ } around the retMenuLists attribute, so it interprets it as a String rather than an expression.

 
Nakata kokuyo
Ranch Hand
Posts: 472
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!