I'm trying to build an HTML table from a collection of Iterable<Object> instances.
final Iterable<Iterable<Object>> rows = Lists.newArrayList(
Lists.newArrayList( 1, "Fizz"),
Lists.newArrayList( 2, "Buzz"),
Lists.newArrayList( 3, null ));
This is added to my model with a key of "rows".
In my template file, I have the following markup:
<#list rows as row>
<tr>
<#list row as value>
<td>${value!}</td>
</#list>
</tr>
</#list>
When I try to print out these values, the template falls over handling the null value of the final row:
freemarker.core._TemplateModelException: The FreeMarker value exists, but has nothing inside it; the TemplateModel object (class: freemarker.ext.beans.StringModel) has returned a null instead of a String. This is possibly a bug in the non-FreeMarker code that builds the data-model.
The blamed expression:
==> value!
I have tried replacing ${value!} with ${value?has_content} and tried a few other combinations <#if value??> around the block, but I keep getting the same error.
How can I make my Freemarker template accept these null values and produce an empty string?
StringModel-s with anullinside come from. The template language can't handle this because it's should happen. - ddekany