In general the use of static method calls in conditions when the return values could
change is not recommended. Things can get wiggy, as you've already seen.
The rule conditions are evaluated when the objects they match on are inserted into working
memory. In your case, though, the rule doesn't match on any object, so the condition
evaluates when the session is created. (That's my guess, at least.) It's NOT when
you call fireAllRules. That only tells the session to fire rules that are currently
eligible to fire. So, if your sequence is this, nothing will happen:
<make session>
ValidationUtilities.evaVersionsNr = "1234";
fireAllRules()
However, this might work:
ValidationUtilities.evaVersionsNr = "1234";
<make session>
fireAllRules()
But, even if it does, it's not a good idea. There's basically no way to inform
the engine that ValidationUtilities.evaVersionsNr has changed, so your results could be
unpredictable. (Especially as ValidationUtilities.evaVersionsNr is a public static member.
Oi!)
--- On Tue, 7/7/09, rainbowflower <al_aysha(a)yahoo.co.in> wrote:
From: rainbowflower <al_aysha(a)yahoo.co.in>
Subject: [rules-users] Problem calling a function returning String
To: rules-users(a)lists.jboss.org
Date: Tuesday, July 7, 2009, 10:33 AM
Hi all,
I am rather new to Drools and I have a problem using
functions.
I have a rule like:
rule "rule 1"
when
eval(getEVAVersionsNr() == "1234")
then
System.out.println("rule fired");
end
The getEVAVersionsNr() method is present in a Java class
"ValidationUtilities.java", which I'm importing in my drl
file and it looks
like this:
public class ValidationUtilities {
public static String evaVersionsNr;
public static String getZEVAVersionsNummer()
{
return evaVersionsNr;
}
}
This static attribute "evaVersionsNr" is set to "1234" from
another Java
class before I fire my rules. So, I assume that the eval
construct should
return true. But, it does not return true and the
consequence is not
exected.
Further info:
When I modify my rule like:
rule "rule 1"
when
eval(true)
then
System.out.println(getEVAVersionsNr());
end
the consequence part is getting executed and 1234 is
getting printed.
I am really lost and I could not find out what goes wrong.
If someone could
find out what I am missing, I shall be thankful.
Thanks in advance.
--
View this message in context:
http://www.nabble.com/Problem-calling-a-function-returning-String-tp24375...
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