Freemarker get element from list
15,137
Solution 1
You can get the second element of the list like this:
${partnerList[1].name}
See the freemarker documentation here.
Solution 2
You can also obtain the name by writing as shown below
<#list partnerList as PARTNER>
<#if PARTNER.partnrid??>
<partnrid>${PARTNER.partnrid}</partnrid>
</#if>
<name>${PARTNER.name}</name>
</#list>
Author by
mkuligowski
Updated on June 04, 2022Comments
-
mkuligowski about 2 years
I am doing teplate which i will use in Smooks conversion. I need to get f.e. 2nd element of the list in freemarker but i have no idea how to do it. There is fragment of my code in freemarker template.
<#list partnerList as PARTNER> ${PARTNER.partnrid} ${PARTNER.name} </#list>
and there is java class:
public class Partner { private String PARTNRID; private String NAME; public String getPartnrid() { return PARTNRID; } public void setPARTNRID(String PARTNRID) { this.PARTNRID = PARTNRID; } public String getName() { return NAME; } public void setNAME(String NAME) { this.NAME = NAME; } }
As i said before i need ONLY 2nd element. I want to avoid printing the rest items. Thanks!