<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">&lt;<a href="mailto:address.good.until.2009.dec.14@justmail.de">address.good.until.2009.dec.14@justmail.de</a>&gt;</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">&gt; Hi, I&#39;m relatively new to both Java and Drools. I&#39;m trying to figure out how<br>
&gt; to use maps in Drools. I&#39;ve looked at the thread<br>
&gt; <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>
&gt;<br>
&gt;&gt;From what I&#39;ve read generally it seems best to insert objects directly<br>
&gt; rather than use nested accessors. So I&#39;ve been experimenting with trying to<br>
&gt; insert a map and then checking stuff in it.<br>
&gt;<br>
&gt; I set up a simple test map of String to Integer, with just &quot;a&quot; as key and 1<br>
&gt; as value, and &quot;b&quot; with 2.<br>
&gt; Map&lt;String, Integer&gt; map = new HashMap&lt;String, Integer&gt;();<br>
&gt; map.put(&quot;a&quot;, 1);<br>
&gt; map.put(&quot;b&quot;, 2);<br>
&gt; String a = &quot;a&quot;;<br>
&gt;<br>
&gt; I then inserted the map and also inserted the String a of value &quot;a&quot;.<br>
&gt;<br>
&gt; Here&#39;s the test rule, with various things I tried commented out:<br>
&gt;<br>
&gt; rule &quot;testing maps&quot;<br>
&gt;       dialect &quot;mvel&quot;<br>
&gt;       when<br>
&gt;               $str: String()<br>
&gt;               // $m: Map( this[$str] == 1 ) # error<br>
&gt;               // $m: Map( this.$str == 1 )   # error<br>
&gt;               // $m: Map( this[&quot;$str&quot;] == 1 ) # compiles but rule won&#39;t fire<br>
&gt;               $m: Map( this[&quot;a&quot;] == 1 ) # this works however!<br>
&gt;       then<br>
&gt;               System.out.println($m[$str]); #also works with String and Map objects &amp; no<br>
&gt; conditions<br>
&gt; end<br>
&gt;<br>
&gt; It obviously doesn&#39;t like it when I try to use the String object as the key<br>
&gt; for the map. But it works when I use a String literal as the key. What am I<br>
&gt; doing wrong?<br>
&gt;<br>
&gt; Does anyone have any suggestions please, or shall I give up and either use<br>
&gt; eval as mentioned in<br>
&gt; <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>
&gt; the map as a field of another object which I insert instead of the map (in<br>
&gt; 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 &quot;a&quot; into it.<br>
Then I wanted to check if Map( this[myVar] == 1 ) but this didn&#39;t work.<br>
<div class="im"><br>
<br>
&gt; I&#39;d also need to test for null i.e. whether a key/value pair exists for a<br>
&gt; 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>