With Drools Rules "mvel" how to iterate over a collection and verify a property for each object in the collection?
Asked
Active
Viewed 1.3k times
2 Answers
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
-
Am I able to use $inter variable in RHS? I have problem with this in Guided Table Editor. – Patryk Dobrowolski Dec 19 '13 at 12:18
-
@PatrykDobrowolski yes – K.C. Mar 20 '14 at 12:42