Java File
for(..){
java.util.List opslist = new ArrayList();
opr.setOperationName(operation.getName()); //gets operation name (iterate and get n no of names) sets it to opr
System.out.println(opr.getOperationName());//gets all the set values n prints it(jus to chack that all values r getting set)
opslist.add(opr.getOperationName());//putting those valies into a list
datamodel.put("opslist", opslist.toArray(new String[]{}));//putting it into a hash map with key as opslist and value as opslist object
}
Freemarker Template
<#list opslist as x> //read the values from the key "opslist" (gets only one value)
${x} //print values one by one(it prints only one value) </#list>
output of the java file is a
get
set
value
usage
output of Freemarket template is
usage
Why is only last value getting printed?
Can someone tell me the right way to do inside freemarker template?
it looks like you are creating a new opslist for each element in your list. in this way only the last element is passed to freemarker.
just put List opslist = new ArrayList(); in front of the for loop