2010/1/4 Esteban Aliverti <span dir="ltr">&lt;<a href="mailto:esteban.aliverti@gmail.com">esteban.aliverti@gmail.com</a>&gt;</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&#39;s inline eval epression, I get the following error: &quot;Cannot use this in a static context&quot; when compiling the rule. I changed</span><div>



<span style="font-family: arial,sans-serif; font-size: 13px; border-collapse: collapse; white-space: nowrap;">&quot;this&quot; by &quot;$c&quot; and it works. I don&#39;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&#39;t have &quot;this&quot;.<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 &quot;Rule1&quot;<br> when<br>   $c:Cheese(type == &quot;chedar&quot;, eval($c.existsInShop (&quot;shopName&quot;))<div class="im">
<br>

 then<br>   System.out.println(&quot;Rule1 is fired&quot;);<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 &quot;<i>this&quot; </i>in rule&#39;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">&lt;<a href="mailto:wolfgang.laun@gmail.com" target="_blank">wolfgang.laun@gmail.com</a>&gt;</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 &quot;inline eval expression&quot; (see the Drools Expert manual),<br>
or an eval conditional element. The first one might be written as:<br>


<br>$c:Cheese(type == &quot;chedar&quot;, eval( this.existsInShop(&quot;shopName&quot;) ) )<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">&lt;<a href="mailto:maya.pollack@gmail.com" target="_blank">maya.pollack@gmail.com</a>&gt;</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&#39;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 &quot;existsInShop&quot; from a rule:<br>
<br>
Rule &quot;Rule1&quot;<br>
  when<br>
    $c:Cheese(type == &quot;chedar&quot;, existsInShop &quot;shopName&quot;)<br>
  then<br>
    System.out.println(&quot;Rule1 is fired&quot;);<br>
end<br>
<br>
I get the compilation error: &quot;no viable alternative at input &quot;shopName&quot; in<br>
rule &quot;Rule1&quot; in pattern document&quot;. 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>