Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

obtain the key of a map

 
nimo frey
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a Map:



Now, I want to get only the keys(name of the keys!!) via JSF-EL:

This


returns the complete map :

{key1=[], key2=[test, hello]}

How can I return the value of the keys?

For example, this does not work:
 
Tim Holloway
Saloon Keeper
Pie
Posts: 17995
47
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You'll need to define a "keys" property on your object. Since there's no "getKeys()" method in the standard Java.util.Map collection, that means you'll need to subclass it with a class of your own that includes getKeys(). Your getKeys() method would need to invoke the Map keySet() method and present the resulting java.util.Set according to how you want it rendered on the page. Usually, you'd want to sort it, since a Set is an unordered collection.
 
nimo frey
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hmm..
I tried it with that, and it works (without implementing a getKey-Property)



To get the values, you can use:




I know, I should avoid using JSTL, but c:forEach works always, where ui:repeat does not work always.

Should I do it that way, when it works?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic