• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

c:forEach not iterating over object fields

 
Ranch Hand
Posts: 1491
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.







 
Bartender
Posts: 7645
178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 1491
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can i access the bean property within forEach ?


 
Tim Moores
Bartender
Posts: 7645
178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What happened when you tried?
 
kri shan
Ranch Hand
Posts: 1491
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No start tag for  </c:forEach> line 7
 
kri shan
Ranch Hand
Posts: 1491
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.


reply
    Bookmark Topic Watch Topic
  • New Topic