I'm trying to populate LinkedHashMap with for loop in order to use it in my jsf page but "put" method of hashmap overwrites the values that is held in hashmap when the new "put" method is fired.
The method is like that;
public static List<String> valuesOfEnum() throws JsonProcessingException { Map<String, Object> newArray = new LinkedHashMap<String, Object>(); List<String> jsonObj = new ArrayList<String>(); String json = null; for(LimanTipi limanTipi : values()){ newArray.put("id", limanTipi.getId()); newArray.put("value", limanTipi.getValue()); json = new ObjectMapper().writeValueAsString(newArray); jsonObj.add(json); } return jsonObj; } Here's the jsf code;
<f:selectItems value="#{denizlimaniViewController.limanTipleri}" var="limanTipleri" itemValue="#{limanTipleri.id}" itemLabel="#{limanTipleri.value}"/> With this method, I convert the hashmap into list as I couldn't populate the hashmap properly but this is not what I want because I can't use this list in <f:selectItems>.
I need to use itemValue and itemLabel representing "id" and "value" properties in hashmap.
Is there a way to handle this?
Thanks
limanTipleri? is this themapnewArray?id,valuekeys are overwrite(that are given hard coded and after for loop execution only two key are there in mapid&valueand the map contain the last overwrited value). You have to create distinct key for veryvalue(limanTipi.getValue())value. You have to create your map something like thatMap<limanTipi.getId()(datatype return by method),limanTipi.getValue()datatype return by method)> map