hell_storm2004 hell_storm2004 - 1 year ago 98
Apache Configuration Question

Adding to List Prints true in Velocity

I am trying to add some string values to a list in Velocity. When I run the code it works alright. But the line where it adds the value prints true. Is it always like that in Velocity? I am new to Velocity templates, so cant figure it out myself.

#set ($uniqueInterfaces = [])
#if($ipv4interfaceName == $ipv6interfaceName)

Its part of larger code with a nested foreach. It has two matches in it, so the output is:


I do not need this true being printed at all!

Answer Source

Java's List#add method returns boolean, that's why this return value is printed in your html output.

You can hide it simply by assigning the output of the add method to a dummy variable:

#set ($uniqueInterfaces     =   [])
#if($ipv4interfaceName == $ipv6interfaceName)
    #set ($swallow = $uniqueInterfaces.add($ipv4interfaceName))
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download