[rules-users] Getting the return from a funcion

Wolfgang Laun wolfgang.laun at gmail.com
Thu Sep 10 02:37:58 EDT 2009


You cannot bind a variable to a function result, as in "$word :
hasForbiddenWordsSet( ... )".

I'd use the original boolean function hasForbiddenWordsSet (which might even
include the check against getTitle() returning null), and add another
function, returning the string, to be called after 'then'.

The first one could be implemented by calling the second one, and comparing
the result to null. Since you probably expect that there aren't too many
"forbidden" words in titles, the performance hit of calling the second one
twice for each firing should be tolerable.

-W


2009/9/9 Leandro Carvalho <leandrodcarvalho at gmail.com>

> Hi! I'm new here and a have a doubt about rules and functions in Drools.
>
> I have this rule:
>
> rule "ProductDescription validation"
>     when
>         $listing : Listing( $description:productDescription != null )
>         eval( $description.getTitle() != null )
>         eval( hasForbiddenWordsSet( wordsSet, $description.getTitle() ) )
>     then
>         System.out.println("ERROR!");
> end
>
> And this function:
>
> function boolean hasForbiddenWordsSet(Set wordsSet, String value) {
> #do something useful here
> }
>
>
> And everything works fine. But now I want that function
> "hasForbiddenWordsSet" return a String. For example to print at "then".
> I tried something like this:
>
> rule "ProductDescription validation"
>     when
>         $listing : Listing( $description:productDescription != null )
>         eval( $description.getTitle() != null )
>         $word : hasForbiddenWordsSet( wordsSet, $description.getTitle() )
>     then
>         System.out.println("ERROR: " + word);
> end
>
> function String hasForbiddenWordsSet(Set wordsSet, String value) {
> #do something useful here
> }
>
> But it doesn't work, tried some other things and still no success.
>
> Could someone help me?
>
> Thanks in advance.
>
> --
> Leandro Carvalho
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20090910/e55208ca/attachment.html 


More information about the rules-users mailing list