Hashmap - JSTL access a MAP via value not by key

De openkb
Aller à : Navigation, rechercher

Sommaire

Questions

this might be an odd question, but I have a map Long-String pair:

10 ANIMAL 11 BACTERIA 12 SHROOM

I send this HashMap from Spring Controller to View:

Map<Long, String> catMap = filterService.generateCatMap();
...
mv.addObject("catMap", catMap);

In the view I can print the key value pair easily by iterating or directly by catMap[ KEY ]

Problem is that I have a JS function where I have to pass the KEY and I know the VALUE. So this is reverse from map: get value by key.

Is it possible actually to get the key by knowing the value without iterating? (I have to mention that keys and values are unique, no duplicates)

Answers

//JSP
<c:forEach var="country" items="${capitalList}">
    Country: ${country.key}  - Capital: ${country.value}
</c:forEach>

See if the above code logic helps. It can help you to retreive both the key and value in the loop. You can use a script function inside the forEach loop and do your required operation as desired.

Source

License : cc by-sa 3.0

http://stackoverflow.com/questions/12881776/jstl-access-a-map-via-value-not-by-key

Related

Outils personnels
Espaces de noms

Variantes
Actions
Navigation
Outils