<br>&nbsp;&nbsp; If you want the &quot;engine to see&quot; your changes, in a way you affect other rules, you must call update( object ) for the object you are changing. Otherwise, the change will happen to the original object, but not to the shadow proxy that the engine uses to ensure consistency.
<br><br>&nbsp;&nbsp; []s<br>&nbsp;&nbsp; Edson<br><br><div><span class="gmail_quote">2007/8/22, pentarious &lt;<a href="mailto:cristiano.giuffrida@gmail.com">cristiano.giuffrida@gmail.com</a>&gt;:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>Ok, I&#39;m still working on that, I&#39;ll publish my solution asap. In the meantime<br>it turns out our requirements need something more than that. We have an<br>ordered list of beans (items) and we have to be able to modify a specific
<br>subset of the list (adding a discount). Now I tried to solve this problem by<br>working directly on the list of items. But I can&#39;t understand why this<br>doesn&#39;t work:<br>when<br>&nbsp;&nbsp;&nbsp;&nbsp; $itemList : ArrayList() from collect( Item( category == &quot;VIDEO&quot; ) )
<br>then<br>&nbsp;&nbsp;&nbsp;&nbsp; ItemDiscount disc = new ItemDiscount(10);<br>&nbsp;&nbsp;&nbsp;&nbsp; $myFirstItem = (Item)$itemList.get(0);<br>&nbsp;&nbsp;&nbsp;&nbsp; $mySecondItem = (Item)$itemList.get(1);<br>&nbsp;&nbsp;&nbsp;&nbsp; $myFirstItem.addDiscount(disc);<br>&nbsp;&nbsp;&nbsp;&nbsp; $mySecondItem.addDiscount(disc);
<br><br>After executing this rule it&#39;s like nothing happened! I mean no discount has<br>been added to the two items! The problem seems to be related to extracting<br>items from the list. Apparently, every time we get an item from the list, it
<br>looses its link with the original item (I don&#39;t know if it&#39;s a copy of the<br>original item or whatever), so that every update doesn&#39;t affect the original<br>item any more. But of course that&#39;s what we&#39;re interested in! We want to
<br>modify original items in the rule session. Am I missing something? Or Is it<br>a bug?<br><br>Regards,<br><br>CG<br><br><br><br>Edson Tirelli-3 wrote:<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; Please, share with us! Send to the list!<br>&gt;
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; Edson<br>&gt;<br>&gt; 2007/8/21, pentarious &lt;<a href="mailto:cristiano.giuffrida@gmail.com">cristiano.giuffrida@gmail.com</a>&gt;:<br>&gt;&gt;<br>&gt;&gt;<br>&gt;&gt; I found an interesting implementation to do that. If anyone is interested
<br>&gt;&gt; I<br>&gt;&gt; could share my solution.<br>&gt;&gt;<br>&gt;&gt; Regards,<br>&gt;&gt;<br>&gt;&gt; CG<br>&gt;&gt;<br>&gt;&gt;<br>&gt;&gt; Mark Proctor wrote:<br>&gt;&gt; &gt;<br>&gt;&gt; &gt; There is no supported way to do this. You could use an inline-eval
<br>&gt;&gt; &gt; against a global, but that is very clunkey. However it does seem like a<br>&gt;&gt; &gt; good feature idea for a future release, open a jira and I&#39;ll look into<br>&gt;&gt; &gt; getting it included.<br>
&gt;&gt; &gt;<br>&gt;&gt; &gt; Mark<br>&gt;&gt; &gt; pentarious wrote:<br>&gt;&gt; &gt;&gt; Does anyone know a method to limit the number of results from a<br>&gt;&gt; collect<br>&gt;&gt; &gt;&gt; statement? I was just wondering how to do something like this:
<br>&gt;&gt; &gt;&gt; $myList : List() from collect( MyObject(myField == &quot;something&quot;) )<br>&gt;&gt; limit<br>&gt;&gt; 3<br>&gt;&gt; &gt;&gt; //it should put in $myList just the first 3 objects retrieved<br>&gt;&gt; &gt;&gt; I&#39;m quite sure there is nothing in Drools which can natively support
<br>&gt;&gt; &gt;&gt; something like that. So, how to do that, if needed? I tried this, but<br>&gt;&gt; it<br>&gt;&gt; &gt;&gt; seems not to be working (I can&#39;t understand why, though):<br>&gt;&gt; &gt;&gt; $myList : List() from collect( MyObject(myField == &quot;something&quot;) )
<br>&gt;&gt; &gt;&gt; $myObject : MyObject() from $myList<br>&gt;&gt; &gt;&gt; eval( $myList.indexOf($myObject) &lt; 3 )<br>&gt;&gt; &gt;&gt; Indeed, it doesn&#39;t work because the link beetween $myList and<br>&gt;&gt; $myObject
<br>&gt;&gt; &gt;&gt; seems to be released during any execution of the rule (In fact<br>&gt;&gt; &gt;&gt; $myList.contains($myObject) returns false! Again, I can&#39;t understand<br>&gt;&gt; &gt;&gt; why...)<br>&gt;&gt; &gt;&gt;
<br>&gt;&gt; &gt;&gt; Any advice would be really appreciated!<br>&gt;&gt; &gt;&gt;<br>&gt;&gt; &gt;&gt; Regards,<br>&gt;&gt; &gt;&gt;<br>&gt;&gt; &gt;&gt; CG<br>&gt;&gt; &gt;&gt;<br>&gt;&gt; &gt;<br>&gt;&gt; &gt; _______________________________________________
<br>&gt;&gt; &gt; rules-users mailing list<br>&gt;&gt; &gt; <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>&gt;&gt; &gt; <a href="https://lists.jboss.org/mailman/listinfo/rules-users">https://lists.jboss.org/mailman/listinfo/rules-users
</a><br>&gt;&gt; &gt;<br>&gt;&gt; &gt;<br>&gt;&gt;<br>&gt;&gt; --<br>&gt;&gt; View this message in context:<br>&gt;&gt; <a href="http://www.nabble.com/How-to-limit-results-from-a-collect-statement-tf4235669.html#a12249025">
http://www.nabble.com/How-to-limit-results-from-a-collect-statement-tf4235669.html#a12249025</a><br>&gt;&gt; Sent from the drools - user mailing list archive at <a href="http://Nabble.com">Nabble.com</a>.<br>&gt;&gt;<br>&gt;&gt; _______________________________________________
<br>&gt;&gt; rules-users mailing list<br>&gt;&gt; <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>&gt;&gt; <a href="https://lists.jboss.org/mailman/listinfo/rules-users">https://lists.jboss.org/mailman/listinfo/rules-users
</a><br>&gt;&gt;<br>&gt;<br>&gt;<br>&gt;<br>&gt; --<br>&gt;&nbsp;&nbsp; Edson Tirelli<br>&gt;&nbsp;&nbsp; Software Engineer - JBoss Rules Core Developer<br>&gt;&nbsp;&nbsp; Office: +55 11 3529-6000<br>&gt;&nbsp;&nbsp; Mobile: +55 11 9287-5646<br>&gt;&nbsp;&nbsp; JBoss, a division of Red Hat @ 
<a href="http://www.jboss.com">www.jboss.com</a><br>&gt;<br>&gt; _______________________________________________<br>&gt; rules-users mailing list<br>&gt; <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org
</a><br>&gt; <a href="https://lists.jboss.org/mailman/listinfo/rules-users">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>&gt;<br>&gt;<br><br>--<br>View this message in context: <a href="http://www.nabble.com/How-to-limit-results-from-a-collect-statement-tf4235669.html#a12270505">
http://www.nabble.com/How-to-limit-results-from-a-collect-statement-tf4235669.html#a12270505</a><br>Sent from the drools - user mailing list archive at <a href="http://Nabble.com">Nabble.com</a>.<br><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">https://lists.jboss.org/mailman/listinfo/rules-users
</a><br></blockquote></div><br><br clear="all"><br>-- <br>&nbsp;&nbsp;Edson Tirelli<br>&nbsp;&nbsp;Software Engineer - JBoss Rules Core Developer<br>&nbsp;&nbsp;Office: +55 11 3529-6000<br>&nbsp;&nbsp;Mobile: +55 11 9287-5646<br>&nbsp;&nbsp;JBoss, a division of Red Hat @ 
<a href="http://www.jboss.com">www.jboss.com</a>