2010/1/4 Esteban Aliverti <span dir="ltr"><<a href="mailto:esteban.aliverti@gmail.com">esteban.aliverti@gmail.com</a>></span><br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Using <span style="font-family: arial,sans-serif; font-size: 13px; border-collapse: collapse; white-space: nowrap;">Wolfgang's inline eval epression, I get the following error: "Cannot use this in a static context" when compiling the rule. I changed</span><div>
<span style="font-family: arial,sans-serif; font-size: 13px; border-collapse: collapse; white-space: nowrap;">"this" by "$c" and it works. I don't know why we are in a static context.</span></div>
<div><span style="font-family: arial,sans-serif; font-size: 13px; border-collapse: collapse; white-space: nowrap;"><br></span></div></blockquote><div><br>Strange. Most likely the compiler converts the inline eval to an eval CE, where you can't have "this".<br>
I have occasionally used <a href="http://s.th">s.th</a>. like<br> $foo : Foo( $bar : bar )<br> Bar( this == $bar )<br>which goaded me into thinking that this.method() should work in an inline eval.<br><br>Thanks for checking this, though!<br>
-W<br><br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div><span style="font-family: arial,sans-serif; font-size: 13px; border-collapse: collapse; white-space: nowrap;">
</span></div><div><span style="font-family: arial,sans-serif; font-size: 13px; border-collapse: collapse; white-space: nowrap;">The rule that worked for me is:</span></div><div><span style="font-family: arial,sans-serif; font-size: 13px; border-collapse: collapse; white-space: nowrap;"><br>
</span></div><div><span style="font-family: arial,sans-serif; font-size: 13px; border-collapse: collapse; white-space: nowrap;"><span style="white-space: normal;">Rule "Rule1"<br> when<br> $c:Cheese(type == "chedar", eval($c.existsInShop ("shopName"))<div class="im">
<br>
then<br> System.out.println("Rule1 is fired");<br>end<br></div></span></span></div><div><span style="font-family: arial,sans-serif; font-size: 13px; border-collapse: collapse; white-space: nowrap;"><br></span></div>
<div>
<span style="font-family: arial,sans-serif; font-size: 13px; border-collapse: collapse; white-space: nowrap;">I attached a working test case. Change $c to "<i>this" </i>in rule's condition and you will see the error I mentioned. </span></div>
<div><span style="font-family: arial,sans-serif; font-size: 13px; border-collapse: collapse; white-space: nowrap;"><br></span></div><div><span style="font-family: arial,sans-serif; font-size: 13px; border-collapse: collapse; white-space: nowrap;">Best, </span><div>
<span style="font-family: arial,sans-serif; font-size: 13px; border-collapse: collapse; white-space: nowrap;"><span style="border-collapse: separate; font-family: arial; white-space: normal; font-size: small;"><br>
</span></span></div><div><span style="font-family: arial,sans-serif; font-size: 13px; border-collapse: collapse; white-space: nowrap;"><span style="border-collapse: separate; font-family: arial; white-space: normal; font-size: small;">2010/1/4 Wolfgang Laun <span dir="ltr"><<a href="mailto:wolfgang.laun@gmail.com" target="_blank">wolfgang.laun@gmail.com</a>></span></span></span><div>
<div></div><div class="h5"><div class="gmail_quote">
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">What you need is called "inline eval expression" (see the Drools Expert manual),<br>
or an eval conditional element. The first one might be written as:<br>
<br>$c:Cheese(type == "chedar", eval( this.existsInShop("shopName") ) )<br><font color="#888888">
<br>-W</font><div><div></div><div><br><br><br><div class="gmail_quote">On Mon, Jan 4, 2010 at 12:49 PM, orchid <span dir="ltr"><<a href="mailto:maya.pollack@gmail.com" target="_blank">maya.pollack@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
Hi All,<br>
<br>
I'm trying to call a class method from the LHS of a rule in the following<br>
way:<br>
<br>
public class Cheese{<br>
private string type;<br>
//setters and getters<br>
public boolean existsInShop(String shop){<br>
...<br>
return true;<br>
}<br>
}<br>
<br>
I would like to call the method "existsInShop" from a rule:<br>
<br>
Rule "Rule1"<br>
when<br>
$c:Cheese(type == "chedar", existsInShop "shopName")<br>
then<br>
System.out.println("Rule1 is fired");<br>
end<br>
<br>
I get the compilation error: "no viable alternative at input "shopName" in<br>
rule "Rule1" in pattern document". How can I call the method from the rule?<br>
<br>
Thanks in advance.<br>
<font color="#888888"><br>
<br>
<br>
--<br>
View this message in context: <a href="http://n3.nabble.com/Call-class-method-from-LHS-of-a-rule-tp108383p108383.html" target="_blank">http://n3.nabble.com/Call-class-method-from-LHS-of-a-rule-tp108383p108383.html</a><br>
Sent from the Drools - User mailing list archive at Nabble.com.<br>
_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org" target="_blank">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>
</font></blockquote></div><br>
</div></div><br>_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org" target="_blank">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>
<br></blockquote></div><br><br clear="all"><br></div></div>-- <br>XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX<br><br>Esteban Aliverti<br>
</div></div>
<br>_______________________________________________<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>
<br></blockquote></div><br>