• 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

c:forEach not iterating over object fields  RSS feed

 
Ranch Hand
Posts: 1490
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

employee list has List of Employee. Inner forEach loop is not printing the employee first name, employee last name and city in each iteration.







 
Saloon Keeper
Posts: 4697
117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're assuming that c:forEach can iterate over JavaBean-style object attributes - not so. Read http://www.ibm.com/developerworks/java/library/j-jstl0318/ to learn what it actually can iterate over.
 
kri shan
Ranch Hand
Posts: 1490
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can i access the bean property within forEach ?


 
Tim Moores
Saloon Keeper
Posts: 4697
117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What happened when you tried?
 
kri shan
Ranch Hand
Posts: 1490
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No start tag for  </c:forEach> line 7
 
kri shan
Ranch Hand
Posts: 1490
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tried this way too and it prints the employee object (not printing first name, last name and city values ).


 
Bartender
Posts: 1844
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There isn't really a nice way to dynamically get all the properties of a bean.  The main issue is getting them in "order". 
How does it know you want first name, then last name?  Or last name then first name?  And should one be bolded but not the other?


Two suggestions:
#1: Specify the properties you want displayed specifically and format them appropriately is often the easiest:


#2:
Got this answer from reading http://stackoverflow.com/questions/14454769/creating-array-using-jstl-or-el




#3:
Make a custom tag for printing out your object.


 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!