<br> Yes, that was a bug that was fixed in newer versions of MVEL. Just update your MVEL jar to 2.0.12.<br><br> []s<br> Edson<br><br><div class="gmail_quote">2009/8/18 André Thieme <span dir="ltr"><<a href="mailto:address.good.until.2009.dec.14@justmail.de">address.good.until.2009.dec.14@justmail.de</a>></span><br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">KDR schrieb:<br>
<div><div></div><div class="h5">> Hi, I'm relatively new to both Java and Drools. I'm trying to figure out how<br>
> to use maps in Drools. I've looked at the thread<br>
> <a href="http://www.mail-archive.com/rules-users@lists.jboss.org/msg09802.html" target="_blank">http://www.mail-archive.com/rules-users@lists.jboss.org/msg09802.html</a><br>
><br>
>>From what I've read generally it seems best to insert objects directly<br>
> rather than use nested accessors. So I've been experimenting with trying to<br>
> insert a map and then checking stuff in it.<br>
><br>
> I set up a simple test map of String to Integer, with just "a" as key and 1<br>
> as value, and "b" with 2.<br>
> Map<String, Integer> map = new HashMap<String, Integer>();<br>
> map.put("a", 1);<br>
> map.put("b", 2);<br>
> String a = "a";<br>
><br>
> I then inserted the map and also inserted the String a of value "a".<br>
><br>
> Here's the test rule, with various things I tried commented out:<br>
><br>
> rule "testing maps"<br>
> dialect "mvel"<br>
> when<br>
> $str: String()<br>
> // $m: Map( this[$str] == 1 ) # error<br>
> // $m: Map( this.$str == 1 ) # error<br>
> // $m: Map( this["$str"] == 1 ) # compiles but rule won't fire<br>
> $m: Map( this["a"] == 1 ) # this works however!<br>
> then<br>
> System.out.println($m[$str]); #also works with String and Map objects & no<br>
> conditions<br>
> end<br>
><br>
> It obviously doesn't like it when I try to use the String object as the key<br>
> for the map. But it works when I use a String literal as the key. What am I<br>
> doing wrong?<br>
><br>
> Does anyone have any suggestions please, or shall I give up and either use<br>
> eval as mentioned in<br>
> <a href="http://www.mail-archive.com/rules-users@lists.jboss.org/msg09716.html" target="_blank">http://www.mail-archive.com/rules-users@lists.jboss.org/msg09716.html</a> or use<br>
> the map as a field of another object which I insert instead of the map (in<br>
> fact that was my original plan!)?<br>
<br>
</div></div>In exactly this thread Marc answered to that problem.<br>
<a href="http://www.mail-archive.com/rules-users@lists.jboss.org/msg09837.html" target="_blank">http://www.mail-archive.com/rules-users@lists.jboss.org/msg09837.html</a><br>
<br>
His first idea is that this is a bug in the mvel dialect.<br>
I tried exactly that. I had a global var and put the string "a" into it.<br>
Then I wanted to check if Map( this[myVar] == 1 ) but this didn't work.<br>
<div class="im"><br>
<br>
> I'd also need to test for null i.e. whether a key/value pair exists for a<br>
> given String as the key.<br>
<br>
</div>This seems to be only true when you go the route that I go, namely using<br>
the default rule syntax, i.e., eval.<br>
<br>
<br>
Sunny greetings,<br>
André<br>
<font color="#888888">--<br>
Lisp is not dead. It’s just the URL that has changed:<br>
<a href="http://clojure.org/" target="_blank">http://clojure.org/</a><br>
</font><div><div></div><div class="h5">_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br> Edson Tirelli<br> JBoss Drools Core Development<br> JBoss by Red Hat @ <a href="http://www.jboss.com">www.jboss.com</a><br>