[rules-users] How to use lists in RHS when using MVEL?
zstlaw
zstlawre at akamai.com
Mon Oct 24 11:17:08 EDT 2011
I want to make an array and pass it to a method in the RHS but can't when I
use mvel. If I use mvel then java new Object[3] causes compile errors. If
I use the mvel syntax the object is not an real array, only a string in
mvel's special array notation which is not useful for the functions I am
trying to call. Working example:
rule "Array bug"
dialect "java" // explicit java or mvel barfs on new Object[];
when
Message( )
then
Object[] logArgs = new Object[3];
logArgs[0] = "Sample string";
logArgs[1] = "Another string";
logArgs[2] = "And done";
System.out.println( "Array was "+$m );
end
If you change dialect above to mvel the code no longer compiles. If you
change it to mvel and use the mvel list syntax ["Sample string", "Another
string", "And done"] you don't have an array so methods requiring an array
do not work. Concrete example: I want to log 3 values using a logging
framework. Many logging frameworks (like sl4j) support a notation like
Logger.warn("My name is {} and you killed my {}", array); where array has
"Inigo Montonya" and "father" for values.
Thanks for any advice!
Zack
--
View this message in context: http://drools.46999.n3.nabble.com/How-to-use-lists-in-RHS-when-using-MVEL-tp3448430p3448430.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
More information about the rules-users
mailing list