• 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
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

EL questions? object method access

 
Ranch Hand
Posts: 251
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Author
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
No matter. Try again. Fail again. Fail better. This time, do it with this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic