<div dir="ltr"><div><div><div><div>I continue to play with the code attached to <a href="https://issues.jboss.org/browse/DROOLS-136">https://issues.jboss.org/browse/DROOLS-136</a> in src.zip. Updated invoice.drl is attached in this mail.<br>
<br></div>I changed the rule "calculate totalPrice per item" to MVEL and trying to calculate and set totalPrice with one liner:<br><br>((DataItemPrice)$v).setTotalPrice(((DataItemPrice)$v).getQty()*((DataItemPrice)$v).getUnitPrice());<br>
<br></div>but that fails with message: java.lang.IllegalArgumentException: object is not an instance of declaring class<br><br></div>On the other hand using temporary variable of type Double will work. Here is the complete rule which works up to the comment "// THIS IS DOESN'T WORK":<br>
<br>rule "calculate totalPrice per item"<br>salience -10<br>no-loop<br>when<br> $q:Message(id=="item", answered==true,<br> value instanceof DataItemPrice, $v:value<br> )<br>then<br> System.out.println("setting totalPrice on item: " + ((DataItemPrice)$v).getName());<br>
<br> System.out.println("qty*unitPrice=" + ((DataItemPrice)$v).getQty()*((DataItemPrice)$v).getUnitPrice());<br> <br><b> Double d = ((DataItemPrice)$v).getQty()*((DataItemPrice)$v).getUnitPrice();<br>
((DataItemPrice)$v).setTotalPrice(d);<br></b> System.out.println("setting via temporary variable worked");<br> <br> // THIS IS DOESN'T WORK<br> <b>((DataItemPrice)$v).setTotalPrice(((DataItemPrice)$v).getQty()*((DataItemPrice)$v).getUnitPrice());</b><br>
System.out.println("setting directly works ???");<br><br> update($q);<br>end<br><br></div>Am I again wrongly hoping that MVEL will simplify data types casting ? Or should I fail a bug ?<br><div><div><br><div>
<div><div><br></div></div></div></div></div></div>