<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:arial,helvetica,sans-serif;font-size:10pt"><div style="font-family: arial,helvetica,sans-serif; font-size: 10pt;">Hi, <br><br>I am placing objects in the Hashmap that were retrieved from the database. There are currently a hundred objects that I'm storing in the HashMap. I just made a simple example earlier :) . What works for me now is putting the getting of the values in the eval(). However, I don't know how to assign the values that I've taken from the Map.<br><br>eval( ( (MyClass)mapOfObj.get("keyOfObj")).getId() > 30);<br><br>How do I assign (MyClass)mapOfObj.get("keyOfObj") to a variable?<br><br><br>tnx,<br><br>shaz<br><br><br><div style="font-family: times new roman,new york,times,serif; font-size: 12pt;">----- Original Message ----<br>From: "Anstis, Michael (M.)" <manstis1@ford.com><br>To: Rules Users List
<rules-users@lists.jboss.org><br>Sent: Friday, November 2, 2007 12:17:51 AM<br>Subject: RE: [rules-users] Accessing maps (hashmaps) keys and values in rules<br><br>
<div dir="ltr" align="left"><span class="886131616-01112007"><font color="#0000ff" face="Arial" size="2">By way of example (if you misunderstand how the rule engine
should be used):-</font></span></div>
<div dir="ltr" align="left"><span class="886131616-01112007"><font color="#0000ff" face="Arial" size="2"></font></span> </div>
<div><font color="#0000ff"><font size="2"><font face="Courier New">rule
chkobj<br>when<br><span class="886131616-01112007"> $o :
</span>MyClass(<span class="886131616-01112007"> </span>id == "1"<span class="886131616-01112007">, </span><span class="886131616-01112007">n</span>ame == "name"<span class="886131616-01112007">
)</span></font></font></font></div>
<div><span class="886131616-01112007"></span><span class="886131616-01112007"></span><font color="#0000ff" size="2"><font face="Courier New">t<span class="886131616-01112007">hen</span></font></font></div>
<div><font><span class="886131616-01112007"></span><font color="#0000ff"><font face="Courier New" size="2"><span class="886131616-01112007"> //Do
something else</span></font></font></font></div>
<div><font><font><span class="886131616-01112007"></span><font color="#0000ff"><font face="Courier New" size="2"><span class="886131616-01112007">
$o.doSomething();</span></font></font></font></font></div>
<div><font><font><font><font><font><font><span class="886131616-01112007"></span><span class="886131616-01112007"></span><font color="#0000ff" face="Courier New" size="2">e<span class="886131616-01112007">nd</span></font></font></font></font></font></font></font></div><br>
<blockquote style="margin-right: 0px;">
<div class="OutlookMessageHeader" dir="ltr" align="left" lang="en-us">
<hr tabindex="-1">
<font face="Tahoma" size="2"><b>From:</b> rules-users-bounces@lists.jboss.org
[mailto:rules-users-bounces@lists.jboss.org] <b>On Behalf Of </b>Edson
Tirelli<br><b>Sent:</b> 01 November 2007 15:48<br><b>To:</b> Rules Users
List<br><b>Subject:</b> Re: [rules-users] Accessing maps (hashmaps) keys and
values in rules<br></font><br></div>
<div></div><br> Shaz,<br><br> We strongly advise you
to move to 4.0.3, but this is not related to your problem. <br> I
think you are misunderstanding something. Why are you using the global map to
store your fact? Simply insert it into the working memory and it will work
fine. <br><br> []s<br> Edson<br><br><br>
<div><span class="gmail_quote">2007/11/1, Shaz Tumulak <<a rel="nofollow" ymailto="mailto:shauii@yahoo.com" target="_blank" href="mailto:shauii@yahoo.com">shauii@yahoo.com</a>>:</span>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>Hi,<br><br>I
can't seem to make this syntax work in Drools 4.0.2. Pls. see my
sample<br>code below.<br>________________________________________<br>class
MyClass {<br> String
id;<br> String
name;<br><br> MyClass(String
id, String
name){<br> <a rel="nofollow" target="_blank" href="http://this.id">this.id</a> =
id;<br> <a rel="nofollow" target="_blank" href="http://this.name">this.name</a> =
name;<br> }<br> :<br> getter,
setter methods
<br> :<br>}<br><br>MyClass
obj = new MyClass("1"", "name");<br><br>TreeMap<String, MyClass>
mapOfObj = new TreeMap<String, MyClass>();<br>mapOfObj.put("keyOfObj",
obj); <br>________________________________________<br><br>DRL
file<br>-------<br><br>global java.util.TreeMap mapOfObj;<br><br>rule
chkobj<br>when<br> obj :
MyClass(mapOfObj["keyOfObj"].id ==
"1");<br> eval(obj.getName()
== "name");<br>________________________________________<br><br>I'm getting
this error:
org.drools.RuntimeDroolsException:<br>java.lang.NullPointerException<br> at
<br>org.drools.rule.EvalCondition.isAllowed(EvalCondition.java:76)<br><br>Is
my syntax correct and has someone used this in 4.0.2 or should I move
on<br>to Drools 4.0.3? Thanks in
advance.<br><br>Regards,<br><br>shaz<br><br><br>Edson Tirelli-3
wrote:<br>><br>> Denis,<br>><br>> If
you are using latest build from trunk (I'm not sure it already works<br>>
in MR3), you can use a simplified MVEL syntax:<br>><br>> when
<br>> Person( address["business"].phone ==
"99999999" )<br>> then<br>> ...<br>>
end<br>><br>> Although, the above will be
converted into an inline-eval. Not as bad<br>> as <br>> a top level
eval, but still more costly then using regular
fields.<br>><br>> []s<br>> Edson<br>><br>>
2007/7/19, Ryan, Dennis (Dennis) <<a rel="nofollow" ymailto="mailto:dennisryan@avaya.com" target="_blank" href="mailto:dennisryan@avaya.com">dennisryan@avaya.com
</a>>:<br>>><br>>> We are using Maps (HashMaps) in
our rules and the only way we have found<br>>> to access keys and
values in the Map in the "when" clauses is thru use on<br>>> eval()
which I know is a big no-no by rules purists. Is there a better <br>>>
way,<br>>> maybe some shorthand I'm not familiar with to deal with
Maps in the when<br>>>
clause?<br>>><br>>><br>>><br>>>
Thanks,<br>>><br>>> Dennis<br>>> <br>>>
_______________________________________________<br>>> rules-users
mailing list<br>>> <a rel="nofollow" ymailto="mailto:rules-users@lists.jboss.org" target="_blank" href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>>>
<a rel="nofollow" target="_blank" href="https://lists.jboss.org/mailman/listinfo/rules-users">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>>><br>>><br>><br>><br>>
--<br>> Edson Tirelli<br>> Software Engineer -
JBoss Rules Core Developer<br>> Office: +55 11 3529-6000
<br>> Mobile: +55 11 9287-5646<br>> JBoss, a
division of Red Hat @ <a rel="nofollow" target="_blank" href="http://www.jboss.com">www.jboss.com</a><br>><br>>
_______________________________________________<br>> rules-users mailing
list <br>> <a rel="nofollow" ymailto="mailto:rules-users@lists.jboss.org" target="_blank" href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>>
<a rel="nofollow" target="_blank" href="https://lists.jboss.org/mailman/listinfo/rules-users">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>>
<br>><br><a rel="nofollow" ymailto="mailto:shauii@yahoo.com" target="_blank" href="mailto:shauii@yahoo.com">shauii@yahoo.com</a><br>--<br>View this
message in context: <a rel="nofollow" target="_blank" href="http://www.nabble.com/Accessing-maps-%28hashmaps%29-keys-and-values-in-rules-tf4112197.html#a13524477">http://www.nabble.com/Accessing-maps-%28hashmaps%29-keys-and-values-in-rules-tf4112197.html#a13524477
</a><br>Sent from the drools - user mailing list archive at <a rel="nofollow" target="_blank" href="http://Nabble.com">Nabble.com</a>.<br><br>_______________________________________________<br>rules-users
mailing list<br><a rel="nofollow" ymailto="mailto:rules-users@lists.jboss.org" target="_blank" href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br><a rel="nofollow" target="_blank" href="https://lists.jboss.org/mailman/listinfo/rules-users">https://lists.jboss.org/mailman/listinfo/rules-users</a><br></blockquote></div><br><br clear="all"><br>-- <br> Edson Tirelli <br> Software
Engineer - JBoss Rules Core Developer<br> Office: +55 11
3529-6000<br> Mobile: +55 11 9287-5646<br> JBoss, a
division of Red Hat @ <a rel="nofollow" target="_blank" href="http://www.jboss.com">www.jboss.com</a>
</blockquote></div><br></div></div><br>
<hr size="1"><FONT face=Arial size=-1>
Platonic friends of the opposite sex - the real deal?<br>Be a better buddy<br>
<a href="http://ph.answers.yahoo.com/dir/index;_ylt=AsCq4OcgSoQ9qZZdke2cnGhL5Qt.;_ylv=3?link=over&sid=396545433">Find out at Yahoo! Answers</a></FONT>
</body></html>