0
votes

I want to loop over the MultiMap in Freemarker template and access(display) the key and its distinct values(which are objects in this case):

Here TaskType is a String (dont misunderstand)

 multiMap.put(TaskType.DHOLDING_TASK,Obj1);
    multiMap.put(TaskType.BTRADE_TASK,Obj2);
    multiMap.put(TaskType.ANONE,Obj3);
    multiMap.put(TaskType.DHOLDING_TASK,Obj4);
    multiMap.put(TaskType.CPRICE_TASK,Obj5);
    multiMap.put(TaskType.BTRADE_TASK,Obj6);
    multiMap.put(TaskType.ANONE,Obj7);
    multiMap.put(TaskType.CPRICE_TASK,Obj8);

The output will look like this of teh MultiMap:

{CPRICE_TASK=[Obj5, Obj8], ANONE=[Obj3, Obj7], BTRADE_TASK=[Obj2, Obj6], DHOLDING_TASK=[Obj1, Obj4]}

My freeMarker code :

<#assign taskKeys = multiMap?keys >
    <#list taskKeys as key>
        ${key} --It works fine till here :-)
    `taskList[key]   or taskList[key_values]---XXX both gives exception 

How to display the multivalues associated with the key here in list???

I need to access the value part o fthe pair here(i.e. the RHS) : CPRICE_TASK=[Obj5, Obj8]

A help is much appreciated :)

1
What does that exception say? I guess that the value is a sequence, which can't be automatically converted to string. Then, you want to do taskList[key]?join(', ') (or #list it). - ddekany

1 Answers

0
votes

Thanks ddekany for the reply.. :) However, I could find the answer, It was mistake in freemarker code..I iterate over the keys as

<#list taskList?keys as taskType>

which is fine ..After that I should be iterating over the list associated with the key (i.e the multiple values)as it is a google multimap.Like:

<#assign values = taskList?values>
  <#list values[taskType_index] as task>

I guess I was missing the assign tag in my code..while accessing the values of the keys. Hope this will help some one.