[rules-users] Possible to use functions in DRL when dialect is mvel?

Wolfgang Laun wolfgang.laun at gmail.com
Tue Jun 19 08:42:53 EDT 2012


It works (5.4.0) with both, Java and MVEL, if all is in the same DRL file.

I'm somewhat surprised that "import" should work for DRL functions,
but I may have missed some development. But your snippets don't show a
DRL import statement?

-W


On 19/06/2012, Stephen Masters <stephen.masters at me.com> wrote:
> Okay Wolfgang ... you asked for it. Here's a version which takes it pretty
> much to the minimum.
>
> The error I see is "Unable to resolve method using strict-mode:
> mypackage.CloneMessage.cloneMessage(mypackage.Message)"
>
> However, the error is only seen when I use mvel dialect. The working Java
> dialect rule is also included below.
>
> Note that when I re-wrote the example function to take a common type such as
> String as argument, then the mvel version worked. It's when the argument is
> a declared type that it fails.
>
> Thanks for taking a look,
>
> Steve
>
>
>
> file - MessageFact.drl
>
>     package mypackage
>
>     declare Message
>         Text: String
>     end
>
>
>
> file - CloneMessage.drl
>
>     package mypackage
>
>     function Message cloneMessage(Message originalMessage) {
>
>         Message newMessage = new Message();
>         newMessage.setText(originalMessage.getText());
>         return newMessage;
>
>     }
>
>
>
> file - SayHelloRuleJava.drl
>
>     package mypackage
>
>     rule "Say hello"
>         dialect "java"
>         lock-on-active true
>         when
>             # Always
>         then
>             Message originalMessage = new Message();
>             originalMessage.setText("Hello, World!");
>
>             Message clonedMessage = cloneMessage(originalMessage);
>
>             insert(clonedMessage);
>     end
>
>
>
> file - SayHelloRuleMvel.drl
>
>     package mypackage
>
>     rule "Say hello"
>         dialect "mvel"
>         lock-on-active true
>         when
>             # Always
>         then
>             Message originalMessage = new Message();
>             originalMessage.Text = "Hello, World!";
>
>             Message clonedMessage = cloneMessage(originalMessage);
>
>             insert(clonedMessage);
>     end
>
>
>
> On Jun 19, 2012, at 12:27 PM, Wolfgang Laun <wolfgang.laun at gmail.com> wrote:
>
> Can you please provide an example where and how you import and use a
> DRL function so that it works/doesn't work with MVEL/Java?
>
> -W
>
>
> On 19/06/2012, Stephen Masters <stephen.masters at me.com> wrote:
>> Hi folks,
>>
>> Is it possible to refer to DRL functions from a DRL when the dialect is
>> mvel?
>>
>> I have been working on unit tests for a rule that were consistently
>> failing
>> due to not being able to find the function that should be imported. Having
>> tried various formats (the documentation is rather unhelpful here) for the
>> import, I thought I'd see what happened if I just switched to the Java
>> dialect. Suddenly it worked without even needing an import statement.
>>
>> Unfortunately, this forces me to switch from the neat ...
>> newFact.Property = otherFact.Property
>> ... to the rather ugly Java-style
>> newFact.setProperty(otherFact.getProperty())
>>
>> So I would quite like to know if there is an undocumented (or
>> well-hidden-documented) mechanism for using functions when in mvel
>> dialect.
>> Or am I stuck with switching to Java?
>>
>> Thanks in advance for any pointers anybody can provide,
>>
>> Steve
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>


More information about the rules-users mailing list