I am doing something similar and having some issues. I am physically
calling setGlobal, but it doesn't seem to be getting set....example....
global String USER_NAME;
rule "Initialize Globals"
salience 100
when
eval(USRE_NAME == null )
then
String name = "Josh";
drools.getWorkingMemory().setGlobal("USER_NAME", name);
System.out.println("Local Name : " + name);
System.out.println("Global Name : " + USER_NAME);
end
This produces
Josh
Null
Not sure I fully follow what is happening.....I am calling setGlobal, but
the value does not appear to get set, thus the null in the last output
statement.
Also any other rule I have set up that utilizes the USER_NAME global won't
fire, ie
rule "Second Rule to Fire"
when
eval(USER_NAME != null)
then
System.out.println("Fired Second Rule);
end
This rule never fires.
Can anyone explain this? And just to clarify, yes, USER_NAME is going to be
immutable once set.
Thanks in advance!
Joshua
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(a)cs.tufts.edu>
To: <rules-users(a)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(a)lists.jboss.org
>
https://lists.jboss.org/mailman/listinfo/rules-users
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
--
View this message in context:
http://www.nabble.com/Initialize-Global-tf4685186.html#a13517718
Sent from the drools - user mailing list archive at
Nabble.com.