Drools rule iterate collections and verify property

13.4k views Asked by At

With Drools Rules "mvel" how to iterate over a collection and verify a property for each object in the collection?

2

There are 2 answers

0
Geoffrey De Smet On BEST ANSWER

Look for the forall keyword in the reference manual (follow documentation on the drools page).

2
Val Schuman On

Here's the code for going over the collection of Interests inside a Person object and checking if one of them is contains an interestName field "Running":

rule "likes running?"
    when
        $p : Person()
        $inter : Interest ( interestName == "Running" ) from $p.interests
    then
        System.out.println("I like running too.");
end