Sorry, please ignore the previous post. Entirely my own stupid mistake, not
enough caffeine obviously! I'd been trying to use a non-String object as the
key, mixing up my objects. Once I extracted the string from it, it was fine.
KDR wrote:
Hi, I'm still having issues with this despite getting the snapshot update
to the mvel jar. Can anyone suggest what else to try please? Am I doing
something wrong?
Say I insert 2 objects:
- ObjectWithKey which has a field that is a string to be used as the key.
- ObjectWithMap has a field that is a map, which contains entries -
including one for the key string that's in the inserted ObjectWithKey.
With the rule below, trying to get the value with the key always produces
null (although with the updated jar at least I no longer get a compilation
error!). However if I use a literal for the key, or from an inserted
String object (the commented out $s below), then it works to print out the
right value for the key.
rule "Tester"
dialect "mvel"
when
# $s : String (this == "aString") # works if I use $s as key
$a : ObjectWithKey (
$k: aStringForKey,
$o: objectWithMap
)
$b: ObjectWithMap (
this == $o,
map != null # works fine, it can see there's a map in existence
# map[$k] != null, # no good, Drools thinks this value is always null
# map[$s] # this works however
)
then
System.out.println("ObjectWithMap has non-null map, value for key is ");
# prints OK
System.out.println($b.map[$k]); # prints out null!
end
I'm at my wit's end. I've also tried Java (with get) and eval alternatives
and can't get it to work. If anyone can suggest a way to get a value out
of the map (for testing against other conditions) when the map is a field
of one object, using a key that is a field in another object, I'd really
appreciate it.
Cheers
--
View this message in context:
http://www.nabble.com/Maps-again---key-derived-from-another-object-tp2509...
Sent from the drools - user mailing list archive at
Nabble.com.