Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List in velocity macro, cannot find contains method

I put a list strings as validTypes in velocity. When I do :

#if (${validTypes}.contains("aaa"))
  // do something
#end

it throws an error. But when I do :

#foreach (${validType} in ${validTypes})
   ${validType}
#end

it works fine. Do I need to use velocity tools for this? How do I use it in an eclipse plugin? Are there any work around without using velocity tools?

like image 801
fastcodejava Avatar asked May 09 '10 23:05

fastcodejava


People also ask

Is Velocity template deprecated?

Velocity templates were deprecated in Liferay Portal 7.0 and are now removed in favor of FreeMarker templates in Liferay DXP 7.2.

What is macro in Velocity?

The #macro directive allows you to name a section of a VTL template and re-insert it multiple times into the template.

How do I add an image to my Velocity template?

1 answer. Or in your Java code, try: URL url = new URL("image. png");

What is Velocityengine in Java?

The Apache Velocity Engine is a free open-source templating engine. Velocity permits you to use a simple yet powerful template language to reference objects defined in Java code. It is written in 100% pure Java and can be easily embedded into your own applications.


2 Answers

The problem here is in curly brackets. Just use

#if (${validTypes.contains("aaa")})

or

#if ($validTypes.contains("aaa"))

instead.

like image 93
serg Avatar answered Oct 12 '22 19:10

serg


For those who concern, this is how to write if not,

#if (!$validTypes.contains("aaa"))
like image 38
Ishan Liyanage Avatar answered Oct 12 '22 18:10

Ishan Liyanage