I've used functions with Drools 5, but not with MVEL. A recent thread seemed to indicate a problem with MVEL for functions, though.<br><br>What you show of your code appears to be OK.<br><br>-W<br><br><div class="gmail_quote">
On Wed, Oct 14, 2009 at 8:35 PM, Chris Richmond <span dir="ltr"><<a href="mailto:crichmond@referentia.com">crichmond@referentia.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Yeah..more fun with functions. I have the following function<br>
<br>
function String getMyValue(){ return "value 1"; }<br>
<br>
I have declared it at the top of the rule file right after all imports and<br>
dialect statement but before any rules<br>
<br>
<imports><br>
global Services services;<br>
global String currentProfilie;<br>
<br>
# setup dialect for the semantic code to be MVEL<br>
dialect "mvel"<br>
<br>
<br>
function String getMyValue(){ return "value 1"; }<br>
<br>
<br>
I then try to call the function from another rule consequence as a test:<br>
<br>
then<br>
System.err.println(getMapRouterAddress());<br>
<other statements which work fine><br>
<br>
<br>
<br>
Now as soon as I start up and the rule file is loaded, I get a null pointer<br>
exception that isn't really helpful as it simpoly points to one of my own<br>
external objects that references the session that failed to load.<br>
<br>
I have tried using functions many times and never successfully done so.<br>
How/where do I place a simple function like this and call it?<br>
<br>
Thanks<br>
<div class="im"><br>
Chris<br>
<br>
<br>
<br>
________________________________________<br>
From: <a href="mailto:rules-users-bounces@lists.jboss.org">rules-users-bounces@lists.jboss.org</a><br>
[mailto:<a href="mailto:rules-users-bounces@lists.jboss.org">rules-users-bounces@lists.jboss.org</a>] On Behalf Of Wolfgang Laun<br>
</div>Sent: Wednesday, October 14, 2009 8:15 AM<br>
<div><div></div><div class="h5">To: Rules Users List<br>
Subject: Re: [rules-users] setting globals in rule file<br>
<br>
You could let the "user" write some functions such as<br>
<br>
function String parFoo(){ return "foo42"; }<br>
<br>
and evaluate them in a rule firing with high priority on eval(true).<br>
<br>
-W<br>
<br>
<br>
2009/10/14 Chris Richmond <<a href="mailto:crichmond@referentia.com">crichmond@referentia.com</a>><br>
Hmm…<br>
<br>
Well..I have this rule file and it seems like a darn convenient place to set<br>
some configuration settings so the user could change them in the plain text<br>
file. Otherwise I have to implement another configuration settgin system<br>
then feed that to th setGlobal…<br>
<br>
Chris<br>
<br>
________________________________________<br>
From: <a href="mailto:rules-users-bounces@lists.jboss.org">rules-users-bounces@lists.jboss.org</a><br>
[mailto:<a href="mailto:rules-users-bounces@lists.jboss.org">rules-users-bounces@lists.jboss.org</a>] On Behalf Of Wolfgang Laun<br>
Sent: Wednesday, October 14, 2009 7:50 AM<br>
To: Rules Users List<br>
Subject: Re: [rules-users] setting globals in rule file<br>
<br>
No, globals can only be set by calling the WorkingMemory method<br>
wm.setGlobal(String name, Object value)<br>
<br>
You could call this in a consequence (RHS), but it's usually not a good idea<br>
to do so.<br>
<br>
What do you want to achieve?<br>
<br>
-W<br>
2009/10/14 Chris Richmond <<a href="mailto:crichmond@referentia.com">crichmond@referentia.com</a>><br>
Shouldn’t it be possible to set a global variable value within the rule file<br>
itself at the top. Something like?<br>
<br>
<br>
global String deviceName = “myDevice”;<br>
<br>
<br>
<br>
I thought you could do that, but consistently get an error saying illegal<br>
character ‘=’ expected “(“<br>
<br>
Or something along those lines.<br>
<br>
This is possible and that syntax should work, shouldn’t it?<br>
<br>
Thanks,<br>
Chris<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" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
<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" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
<br>
<br>
<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" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</div></div></blockquote></div><br>