[rules-users] Initialize Global

vdelbart delbart.v at mipih.fr
Tue Oct 30 04:56:09 EDT 2007


If your List is not immutable, you can't use global. You have to use WM
facts.

V.


java_user_ wrote:
> 
> Thanks.
> 
> That initialized my global but the rule still runs every execution.  Can I
> disable the rule after the first execution?  
> 
> I would like to use (if (objectList==null)).  My list is not immutable. 
> Can I make a similar rule for the LHS?
> 
> 
> 
> Kris Verlaenen wrote:
>> 
>> You can create a rule that initializes your global, preferrably with a
>> high 
>> salience so it gets executed first:
>> 
>> rule "InitializeGlobal" salience 100
>>   when
>>   then
>>     ArrayList objectList = new ArrayList();
>>     objectList.add("1");
>>     objectList.add("2");
>>     drools.getWorkingMemory().setGlobal("objectList", objectList);
>> end
>> 
>> Kris
>> 
>> ----- Original Message ----- 
>> From: "drools_user" <jkraemer at cs.tufts.edu>
>> To: <rules-users at lists.jboss.org>
>> Sent: Wednesday, October 24, 2007 7:35 PM
>> Subject: [rules-users] Initialize Global
>> 
>> 
>>>
>>> How do I initialize a global fact in the drl file?  I want use the JSR94 
>>> API
>>> and avoid using the Drools API inside the Java code.  I would like to 
>>> access
>>> the same variable every execution of a stateful session without having
>>> to
>>> reinstantiate the variable after each execution?
>>>
>>> Basically I want to define a global like this:
>>> # Define global variable
>>> global List objectList ;
>>>
>>> # Part that does not work
>>> objectList = new ArrayList() ;
>>> objectList.add("1");
>>> objectList.add("2");
>>>
>>>
>>> Thanks
>>> -- 
>>> View this message in context: 
>>> http://www.nabble.com/Initialize-Global-tf4685186.html#a13388685
>>> Sent from the drools - user mailing list archive at Nabble.com.
>>>
>>> _______________________________________________
>>> rules-users mailing list
>>> rules-users at lists.jboss.org
>>> https://lists.jboss.org/mailman/listinfo/rules-users 
>> 
>> _______________________________________________
>> rules-users mailing list
>> rules-users at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/rules-users
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Initialize-Global-tf4685186.html#a13484636
Sent from the drools - user mailing list archive at Nabble.com.




More information about the rules-users mailing list