• Post Reply Bookmark Topic Watch Topic
  • New Topic

Accessing Object Methods In An ArrayList Using c:forEach?  RSS feed

 
Marcus Hathaway
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

Is there a way to access the methods of an object within an ArrayList in a JSP without scripting? For instance using java like below i could call variable get methods in order to find out details about a basket item.



Assuming i'm using a bean that will return the ArrayList 'basketItems', can i set different var properties of the c:forEach tag (assuming c:forEach will be able to perform the operation)?

Any advice would be greatly appreciated (as always!)
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66154
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To tell you the truth I couldn't make out what you are asking, but iterating over a list of beans is completely straight-forward.

Something like:



The listed items must be true JavaBeans, and you can only access properties of the bean, not general methods.
[ March 28, 2006: Message edited by: Bear Bibeault ]
 
Marcus Hathaway
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for not explaining very well!

But thank you anyway....what you have suggested solved my problem, never imagined it would be so straightforward.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66154
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The combination of the JSTL and the EL is a powerful tool for simplifying JSP pages dramatically. The key is making sure that the data sent to the JSP pages conforms to EL-friendly structures. Lists (and other collections), arrays, Maps and JavaBeans make for straight-forward and easy access.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!