<select name="showYears">
<#list payrollYears as year>
<option value="${year.year}">${year.yeardesc}</option>
</#list>
</select>
i am getting payrollyears list from my controller and i am iterating the list in freemarker and adding value to select box i want my last value of list should be selected value in last how can i do that
You could do something like
<#list payrollYears as year>
<option value="${year.year}" <#if !(year_has_next)>selected</#if> >${year.yeardesc}</option>
</#list>
For FreeMarker 2.3.24, you can do something like year?has_next
instead of year_has_next
.
item_has_next
(deprecated by item?has_next
): Boolean value that tells if the current item is the last in the sequence or not.See FreeMarker Docs
<#list body.result as school_names_list>
{
"NAME": <#if school_names_list.NAME??>"${school_names_list.NAME}"<#else>""</#if>,
"ADDRESS": <#if school_names_list.ADDRESS??>"${school_names_list.ADDRESS}"<#else>""</#if>,
<#if school_names_list?is_last><#else>,</#if>
</#list>
//Here **school_names_list** is a list and we check the last element though **school_names_list?is_last** (where list name is school_names_list)
//In this example, if it the last element, ***we'll avoid adding "," else we add "," as per JSON rules of a list.***
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With