Search code examples
droolsmvel

Mvel expression not working in Drools


I have the following Java rule in a Drools LHS:

Policy(((Person)contacts.get(0)).getHouseHold() == null)

This works. I was expecting that I could change that to an mvel expression like this:

Policy(contacts[0]#Person.houseHold == null)

or this:

Policy((contacts[0])#Person.houseHold == null)

or even this:

Policy(((contacts[0])#Person).houseHold == null)

This however gives the following error when I compile the drools rules:

mismatched input '#' in rule "Rule1"

What's wrong with my mvel expression?


Solution

  • This works:

    $contact: contacts[0], $contact#Person.houseHold == null
    

    I guess mvel or drools cannot handle a typecast of an element of a list directly.