Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if a map is empty in Apache Velocity

In my java/spring app, I have a velocity template in which I create a map which will hold values also inserted in the template:

#set ($myMap = {})

What I want to do is have an if/else checking if the map is empty. This doesn't seem to be working for me. I've tried:

#if ($myMap.empty)
...
#if ($myMap.size == 0)

Neither of these work. What is the correct way to check if a Map is empty in velocity. I've tried searching the Documentation and SO, but I can't find an example.

like image 225
John Farrelly Avatar asked Jan 04 '13 12:01

John Farrelly


1 Answers

isEmpty and size are methods, so they should be used like this:

#if ($myMap.isEmpty())
...
#if ($myMap.size() == 0)
like image 54
GOTO 0 Avatar answered Nov 18 '22 23:11

GOTO 0