File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

howto use JSTL foreach to display list ?

 
Nakata kokuyo
Ranch Hand
Posts: 465
  • 0
  • 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 ]
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • 0
  • 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: 465
  • 0
  • 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 ?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64205
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • 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: 465
  • 0
  • 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
 
Stefan Evans
Bartender
Posts: 1640
9
  • 0
  • 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: 465
  • 0
  • 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
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic