File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSF and the fly likes obtain the key of a map Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "obtain the key of a map" Watch "obtain the key of a map" New topic

obtain the key of a map

nimo frey
Ranch Hand

Joined: Jun 28, 2008
Posts: 580
I have a Map:

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


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

Joined: Jun 25, 2001
Posts: 17417

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.

An IDE is no substitute for an Intelligent Developer.
nimo frey
Ranch Hand

Joined: Jun 28, 2008
Posts: 580
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?
I agree. Here's the link:
subject: obtain the key of a map
It's not a secret anymore!