This week's book giveaway is in the Spring forum.
We're giving away four copies of Spring in Action (5th edition) and have Craig Walls on-line!
See this thread for details.
Win a copy of Spring in Action (5th edition) this week in the Spring 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:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

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 ?
 
Marshal
Posts: 67164
169
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: 1845
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
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!