I have a Map whose key and value and custom classes. The key class is called Position
and is instantiated with two int (for example new Position(2, 4)
.
I got rid of this Position class and converted the map to a SimpleHash
in order to use it with Freemarker. I now have a SimpleHash
whose key is a String remapping Position values (for example "2 4"
) and whose value is either null
or a Lot
(custom) class.
In the template I need to check if the value of a given item in the SimpleMap (passed as map
) is either null or a Lot instance.
<#list mapMinY..mapMaxY as y>
<tr>
<#list mapMinX..mapMaxX as x>
<td>
<div>
<!-- Check if map[x + " " + y] is null -->
${x}, ${y}
</div>
</td>
</#list>
</tr>
</#list>
How to do this?
Use the ??
operator.
<#if map[x + " " + y]??>It's not null<#else>It's null or missing</#if>
See also the related part of the Manual.
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