File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
Author

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:

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

Joined: Jun 25, 2001
Posts: 15957
    
  19

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
nimo frey
Ranch Hand

Joined: Jun 28, 2008
Posts: 580
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?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: obtain the key of a map
 
Similar Threads
jaxb hashmap?
IllegalArgumentException: more than 10 parameters
Map instantiate with key-value
Hashmap and Generics
Map within a Map in JSF-EL ?