From: Peter S. <sh...@ya...> - 2005-04-14 21:52:44
|
I want to be able to find out if $myVar is in $mylist. Is there syntax to handle this w/ WM template scripting? ## Here is my list #set $myList = [ "one", "two", "three" ] ## Here is the variable I'm looking for #set $myVar = "two" ## I want to do this #if ( $myVar in $myList ) { do something... } #else { do something else... } In my particular case, $myList is a java.util.Vector made up of composite objects - each object has a name, value, etc. To keep maintenance simple, I wanted to avoid doing a multiple-condition 'if' statement like this: #if ( ($myVar==$possibility1) || ($myVar==$possibility2) || ($myVar==$possibility3) etc. ) ) { do something... } #else... To give a fuller picture, my close-to-ideal pseudo-code looks like this: #set $myList = [ "one", "two", "three" ] #foreach $compositeObj in $someRuntimeList { #if ($compositeObj.name in $myList) { do something } #else { do something else... } } I've tried to turn around the 'if' condition using this syntax: #if ($myList.contains($compositeObj.name)) { but I get a 'NoSuchMethodException on a Ljava.lang.Object'. Thanks for any pointers. I'm willing to do some coding if we wanted to add this to the codebase - only, not sure if I could even understand enough of the engine (Expression.java maybe?) to know where to start hacking. __________________________________ Do you Yahoo!? Yahoo! Small Business - Try our new resources site! http://smallbusiness.yahoo.com/resources/ |