6

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

joshjdevl
  • 7,092
  • 12
  • 45
  • 57

2 Answers2

6

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

Geoffrey De Smet
  • 26,223
  • 11
  • 73
  • 120
4

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
Val Schuman
  • 1,798
  • 2
  • 18
  • 23