• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EL questions? object method access

 
Phil Chuang
Ranch Hand
Posts: 251
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I have a bean that wraps around a map, and has two methods: getValues and getKeySet, would I be able to do
{$something.values}
and call the getValues() method? Or does it look for an actual, physical bean property?
 
Kevin Jones
Author
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you have a bean that has a getValues method then ${something.values} will give you whatever getValues returns. Depending on how this is used it may or may not be useful to you. looking at Map, the values() method returns a collection, so if you pass the result of ${something.values} to a tag that is expecting a Map then you will be golden. However if you simply output the value of ${something.values} to the page (in a JSP 2.0 page), then the EL will call toString on the value returned and you will probably get the Object.toString() value printed out.
If you want access to the values or keys of the Map then use the forEach tag from the JSTL.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic